Core tips:system services in the boot generally can automatically start, that under the Linux system if you want the program to start automatically when the boot? We know that in the Windows system "start" and "All Programs" and "Start" put a shortcut on the line, What about the Linux system? ... System services in the boot generally can automatically start, that under the Linux system if you want the program to start automatically when the boot? We know that in the Windows system "start" and "All Programs" and "Start" put a shortcut on the line, the Linux system?
This is also a relatively simple problem, there are many ways to solve, here are three ways to introduce. Because it is a simple introduction, so the details are not very detailed, you can see the manual through the man.
First,/etc/rc.local
This is the simplest way to edit "/etc/rc.local" to enter the shell command of the launcher (to enter the full path of the command), similar to "Start" under Windows.
using the command VI /etc/rc.local
Then add the full path of the program to execute on the last line of the file.
For example, each time you turn on a haha.sh, this script is placed under/OPT, you can add a line "/opt/./haha.sh" in "/etc/rc.local", or two lines of "cd/opt" and "./haha.sh".
Second, crontab (similar to the Windows Task Scheduler service)
with Crontab, you can set a program's execution schedule, for example, to have the program run at 8 points per day, or 10 points per Monday.
Crontab-l lists the timetable;
crontab-e Editing schedule;
crontab-d Delete schedule;
"-L" nothing to say, is a view;
"-E" is an editor, and VI is no different (in fact, with VI editing a specific file);
"-D" is basically not used, because it removes all of the user's schedule, usually with the "-E" editor to delete the time-line;
So how do you edit it?
the format of the crontab file is: M H d M D CMD.
a 6 field, where the last cmd is the program to execute, such as haha.sh.
M: Minutes (0-59)
h: Hours (0-23)
D: Date (1-31)
m: Month (1-12)
D: One day of the one week (0-6, 0 for Sunday)
These 5 time fields are separated by a space with a value that can be a number or a comma-separated number (or other), or "*" If you do not need to set it.
For example, a daily 8:5 execution haha.sh is "5 8 * * */opt/./haha.sh".
as if and "boot program automatically start" Pull away, now return to the point. In fact, the above introduction of the CRONTAB function has the ability to boot automatically start, you can write a monitoring script, every 5 minutes (*/5 * * * *./haha.sh), if the program is not in the restart.
Third, registration system services
Operating Systemself-brought services, such as ssh,ftp and so on, the boot is automatically started, we can also use this way to develop their own programs to improve the "price."
For example, if I want to add a service that is already installed as a system service, you can execute the following command:
chkconfig--add Service name (First, add as system service, note that add is preceded by two bars)
Chkconfig-leve Boot level service name on
(Description, Level 3 is started in the command line mode, Level 5 represents the start in the graphical interface, on means open)
Chkconfig-leve Boot level service name off
(description, off means off-boot)
example: chkconfig-level 3 MySQL on & nbsp &NBSP, ( Description: Let the MySQL service in command-line mode, boot with system)
You can also use the Chkconfig--add service name to remove system services
******************************************************************************************
If you want to see which services are added as system services, you can use the command:
ntsysv or chkconfig--list .
If you want to see which programs are added as self-booting, you can use the command:
cat/etc/rc.local (see which program paths are added to this file)
*******************************************************************************************
Let's say, for example, how to add a shell script as a system service and follow the system boot up:
you can see that there are a lot of files under "/etc/rc.d/init.d", each one can see the content, in fact, some shell scripts.
The startup of the system service is implemented through the script file in "/etc/rc.d/init.d". We can also write a script of our own to put here.
the contents of the script file are also very simple, similar to this (for example, a name called "Hahad"):
./etc/init.d/functions
start () {
echo "Starting my Process"
cd/opt
./haha.sh
}
Stop () {
Killall haha.sh
echo "stoped"
}
after you've written the script file, it's not over yet, so go ahead and complete the following steps:
chmod +x Hahad #增加执行权限
Chkconfig--add Hahad #把hahad添加到系统服务列表
Chkconfig Hahad on #设定hahad的开关 (on/off)
chkconfig--list Hahad #就可以看到已经注册了hahad的服务
It was time to finish all the work.
This article is from the "Dream to Reality" blog, please be sure to keep this source http://lookingdream.blog.51cto.com/5177800/1795889
How the Linux system starts automatically when the program is powered on