System services can generally be automatically started at startup. What programs do we write ourselves?
In windows, just put a shortcut in "start"> "All Programs"> "start". What about Linux?
This is also a simple problem. There are many ways to solve it. here we will introduce three methods. Because it is a simple introduction, the details are not very detailed. You can refer to man to see the relevant manual.
I./etc/rc. local
This is the simplest method. Edit "/etc/rc. local" and enter the shell command of the Startup Program, which is similar to "start" in windows ".
For example, you need to run a haha command every time you start the system. sh, put this script under/opt, then you can go to "/etc/rc. add a line "/opt /. /haha. sh, or two "cd/opt" and ". /haha. sh ".
Ii. crontab
You can use crontab to set the program execution schedule, for example, to run the program at every day or at every Monday.
Crontab-l: list the schedules;
Crontab-e: edit the schedule;
Crontab-d: delete a schedule;
There is nothing to say about "-l". It's just a look;
"-E" is editing, which is no different from vi (in fact, it is to use vi to edit a specific file );
"-D" is basically not used because it deletes all the user's timelines. Generally, "-e" is used to edit and delete the unwanted timelines line by line;
So how should we edit it?
The format of the crontab file is m h d m d CMD.
The last CMD is the program to be executed, such as haha. sh.
M: minute (0-59)
H: hour (0-23)
D: Date (1-31)
M: Month (1-12)
D: one day in a week (0-6, 0 represents Sunday)
These five time fields are separated by spaces. The value can be a number or multiple numbers (or others) separated by commas (,). If you do not need to set them, the default value is "*".
For example, run haha. sh at 08:05 every day, that is, "5 8 ***/opt/./haha. sh ".
It seems that it is far from "Automatic startup of the boot program". Now we are back to the question. In fact, the crontab function described above already has the ability to start automatically at startup. You can write a monitoring script and execute it every 5 minutes (*/5 ****. /haha. sh). If the program is absent, restart it once.
3. Register System Services
Services provided by the operating system, such as ssh and ftp, are automatically started upon startup. We can also use this method to increase the value of our programs ".
We can see that there are a lot of files under "/etc/rc. d/init. d", and each file can see the content, which is actually a shell script.
The system service is started through the script file in "/etc/rc. d/init. d. You can also write your own script here.
The content of the script file is also very simple, similar to this (for example, the name is "hahad "):
./Etc/init. d/functions
Start (){
Echo "Starting my process"
Cd/opt
./Haha. sh
}
Stop (){
Killall haha. sh
Echo "Stoped"
}
After the script file is written, complete the following steps:
Chmod + x hahad # Add execution permission
Chkconfig -- add hahad # add hahad to the System Service list
Chkconfig hahad on # Set the hahad switch (on/off)
Chkconfig -- list hahad # You can see that the hahad service has been registered.
This completes all the work.