Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add Boot Boot items in linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about how to add boot items in linux, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Use the chkconfig command to view the services (or programs) that start automatically at different startup levels. The command format is as follows:

Chkconfig-list

The possible output is as follows:

Openvpn 0: off 1: on. 6: off (0-6 is the startup level; off / on is the automatic start option for the service at the appropriate level)

If you want to make changes to the auto-start option, the command format is:

Chkconfig-level x name on/off

Z.B. Chkconfig-- level 5 openvpn off

The above command can query the services provided by the system. If you want to start a program when you boot, you can use the following methods:

Add the name of the software you want to start on the last line of the ~ / .bash_profile file. For example, "synergyc 192.168.0.154" automatically runs synergyc and connects with 192.168.0.154 when it is turned on.

The above is for my personal configuration, but I found a problem: FC12 does not start the system until after logging in, that is to say, synergyc has not been started when entering the user login interface. So, (perhaps) synergyc is not suitable to be installed in a linux system used as a keyless mouse client.

Run the program automatically in Red Hat Linux

1. Run the program automatically when you start up

After Linux loads, it initializes the hardware and device drivers, and then runs the first process, init. Init continues the boot process based on the configuration file to start other processes. In general, modifying the script file placed in the / etc/rc or / etc/rc.d or / etc/rc?.d directory allows init to start other programs automatically. For example: edit / etc/rc.d/rc.local file, add a line "xinit" or "startx" at the end of the file, you can enter X-Window directly after boot.

2. Run the program automatically when you log in

When a user logs in, bash first automatically executes the global login script: / etc/profile established by the system administrator. Bash then looks for one of the three special files in order under the user's starting directory: / .bash_profile, / .bash_login, / .profile, but only executes the one found first.

Therefore, you can automatically run some programs when users log in (similar to Autoexec.bat under DOS) by adding commands to the above files according to their actual needs.

3. Run the program automatically when you log out

When you log out, bash automatically executes the personal login script /. Bash_logout. For example, if you add the command "tar-cvzf c.source.tgz * .c" to / .bash_logout, the "tar" command is automatically executed to back up the * .c file each time you log out.

4. Run the program automatically on a regular basis

Linux has a daemon called crond, whose main function is to periodically check the contents of a set of command files in the / var/spool/cron directory and execute the commands in those files at a set time. Users can create, modify, and delete these command files through the crontab command.

For example, create a file crondFile with the contents of "00 9 23 Jan * HappyBirthday". After running the "crontab cronFile" command, the system automatically executes the program "HappyBirthday" whenever it is 9:00 on January 23 ("*" means no matter what day it is).

5. Run the program automatically on a regular basis

The regular execution command at is similar to crond (but it executes only once): the command is executed at a given time, but is not automatically repeated. The general format of the at command is: at [- f file] time, which executes all commands given in the file file at a specified time. You can also enter commands directly from the keyboard:

The code is as follows:

$at 12:00

At > mailto Roger-s "Have a lunch"

< plan.txt at>

Ctr-D

Job 1 at 2000 Mui 11 09 12:00

At 12: 00, an email entitled "Have a lunch" with the content of the plan.txt file will be sent to Roger automatically.

#! / bin/bash

RESTART= "." # write the corresponding service code

START= "."

STOP= "."

Case "$1" in

Restart)

$RESTART

Echo "."

Start)

$START

Echo "."

STOP)

$STOP

Echo "."

*)

Echo "Usage: $0 {restart start stop}"

Exit 1

Esac

Exit 1

After the script is written, you need to modify the permission chmod Unitx test.sh.

First of all, the service programs started randomly by linux are in the / etc/init.d folder, and all the files inside are script files (the script program simply writes the program to be run in a file so that the system can execute sequentially, similar to the autorun.dat file under windows). In addition, there are folders such as rc1.d, rc2.d and rc6.d in the / etc folder. These are all different runlevel of linux. The run level of the X windows multi-user we enter is level 5, that is, rc5.d. The script file under this folder is the service program that needs to be started randomly when running level 5. It should be noted that the files under each rc (1-6) .d folder are actually a soft connection to the files under the / etc/init.d folder (similar to the shortcuts in windows), that is, under the / etc/init.d folder are all the service programs, while each rc (1-6) .d links only the corresponding service programs it needs to start!

To start scim (a program), we first need to know where the scim program is, which can be found with the locate command, scim in / usr/bin/scim, where usr belongs to the user, and bin represents the executable program in linux. In this way, I can write a script, put it in / etc/init.d, and then make a corresponding soft link in rc5.d.

This script is actually very simple, just two lines:

#! / bin/bash

/ usr/bin/scim

The first line is to declare what terminal to use to run the script, and the second line is the command to run.

It is also important to note that in rc5.d, the name of each link starts with S or K, S means that the system starts randomly, and K starts not randomly. In this way, you can know that if I want a service to start randomly, just change its name from K to S, of course, after changing S to K, the service cannot be started at random. Therefore, my link will be named SXXX so that the system can start it at random.

Add a self-startup script

First put your script in / etc/init.d, and then execute the following instructions:

Update-rc.d a start 90 2 3 4 5. Stop 90 0 1 6.

Where an is your script, notice that there are two points.

A sample script.

The code is as follows:

#! / bin/sh

# Source function library.

If [- f / etc/init.d/functions]; then

. / etc/init.d/functions

Else

. / lib/lsb/init-functions

Fi

MOD=/a.ko

Start ()

{

Echo-n $"insert a kernel module:"

/ sbin/insmod $MOD

Echo

}

Stop ()

{

Echo-n $"remove a kernel module:"

/ sbin/rmmod a-f

Echo

}

[- f $MOD] | | exit 0

# See how we were called.

Case "$1" in

Start)

Start

Stop)

Stop

Restart | reload)

Stop

Start

*)

Echo $"Usage: $0 {start | stop | restart | reload}"

The update-rc.d command is used to automatically upgrade the System V type initialization script. To put it simply, you can use it to set up what you want the system to run during boot initialization and which you want to stop on shutdown or restart. The connection to these scripts is located at / etc/rcn.d/LnName, and the corresponding script is located at / etc/init.d/Script-name.

1. Set the startup items that specify the startup order and the running level:

Update-rc.d < service > start < order > < runlevels >

2. Set in the specified run level and stop in the specified order:

Update-rc.d < service > stop < order > < runlevels >

3. Delete the specified startup item from all run levels:

Update-rc.d-f < script-name > remove

For example:

Update-rc.d script-name start 90 1 2 3 4 5. Stop 52 0 6.

Start 90 1 2 3 4 5. It means that in the five run levels 1, 2, 3, 4 and 5, the script starts to run in the 90th run level, from small to large.

Stop 52 0 6. : means that in the two run levels 0 and 6, in order, from small to large, the 52nd stop the script.

If you add a script to / etc/init.d, you also need to make the relevant link

In / etc/rc*.d. K starts with kill, S starts with start, and the numerical order represents the order in which to start. (SysV)

Update-rc.d can help you.

Example:

Create a script called zope in / etc/init.d, and then

Update-rc.d zope defaults

The following chains will be generated:

The code is as follows:

Adding system startup for / etc/init.d/zope...

/ etc/rc0.d/K20zope->.. / init.d/zope

/ etc/rc1.d/K20zope->.. / init.d/zope

/ etc/rc6.d/K20zope->.. / init.d/zope

/ etc/rc2.d/S20zope->.. / init.d/zope

/ etc/rc3.d/S20zope->.. / init.d/zope

/ etc/rc4.d/S20zope->.. / init.d/zope

/ etc/rc5.d/S20zope->.. / init.d/zope

For other advanced uses, please man update-rc.d

The above is how to add boot items in linux, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report