Linux Setup boot up

Source: Internet
Author: User

How the Linux system starts automatically when the program is powered on



Core TIP: The system's services can be started automatically when booting, that under the Linux system if you want the program to start automatically when the boot? We know that in the Windows system "start"-"All Programs"-and "start" 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 system comes with services, such as SSH,FTP, etc., 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 (description: Let 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的服务

That's when all the work is done.

Linux Setup boot up

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.