Linux Setup boot entry two ways

Source: Internet
Author: User

Original link: http://blog.csdn.net/karchar/article/details/52489572

Sometimes we need the Linux system to automatically load some scripts or system services when booting up.

Take a look at the Linux startup process before solving the problem

Linux Start-up process

The main sequence is:
1. Loading the kernel
2. Start the initialization process
3. Determine the operating level
4. Load Boot startup program
5. User Login

Specific details of the startup process can be seen in the Linux startup process

The 4th step to load the startup program is actually two steps:

    1. The init process loads the boot program one by one, actually running the startup script in the specified directory .
    2. After running the program in the specified directory, the INIT process also executes the/etc/rc.local script.

PS: "specified directory" refers to the directory that corresponds to the runlevel set in step 3rd.

To fulfill our needs, we can use either of the 4th steps.

The following are the specific implementations of these two approaches:

1.chkconfig

Take the Supervisord service script as an example:

#!/bin/sh### #/etc/rc.d/init.d/supervisord###supervisor is a client/server system# allows its users to monitor and control a# Number of processes on unix-like operating# systems.## Chkconfig:-64 36# Description:supervisor Server# Processname:supervisord# Source init functions. /etc/rc.d/init.d/functionsprog="Supervisord" prefix="/usr/" exec_prefix="${prefix}" pidfile="/var/run/supervisord.pid" config="/etc/supervisord.conf" prog_bin="${exec_prefix}bin/supervisord-c $CONFIG" function log_success_msg () {echo"[Email protected]""[OK]"}function log_failure_msg () {echo"[Email protected]""[OK]"}start () {#echo-N $ "Starting $prog:"#daemon $prog _bin--pidfile $PIDFILE#[-F $PIDFILE] && success $ "$prog Startup" | | Failure $ "$prog failed"#echoif [!-R $CONFIG]; Then log_failure_msg"Config file doesn ' t exist (or you don ' t has permission to view)" Exit4 fiIf [-e $PIDFILE]; Then pid="$ (pgrep-f $PIDFILE)"If Test-n"$PID" && kill-0  "$PID" &>/dev/null; then # If the status is SUCCESS then don ' t need to start again. Log_failure_msg  "$NAME process is running" Exit 0 fi fi log_success _msg  "starting the process"  "$prog" daemon $prog _bin--pidfile $ Pidfile log_success_msg  "$prog process was started"}stop () {echo-n $  "$prog shutdown" echo}case  "$" in start) start; stop) stop;; status) status $prog;; restart) stop start;; *) echo             

1th step: Put the above script under the/etc/init.d/folder.

ln -s ./supervisord  /etc/init.d/supervisord

2nd Step: Change the startup script permission to executable.

chmod a+x /etc/init.d/supervisord

3rd Step: Add the Startup item.

chkconfig --add supervisordchkconfig supervisord on

4th Step: Check if the setting is successful.

chkconfig --list | grep supervisordsupervisord     0:关闭    1:关闭    2:启用    3:启用    4:启用 5:启用 6:关闭

Success ~

2. Modify the/etc/rc.local script

/etc/rc.local script content is as follows

#!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don‘t# want to do the full Sys V style init stuff.#touch /var/lock/subsys/localecho "hello linux" >> /tmp/hello2.loginfluxd > /tmp/influxd.log 2>&1 &echo "hello linux" >> /tmp/hello3.log

echo "Hello Linux" >>/tmp/hello2.log, simulates a simple boot-up script.

Influxd is to start the Influxd service.

PS: influxd > /tmp/influxd.log 2>&1 & The meaning of this writing is to let the influxd backstage execution.

Influxd and the previous echo "hello linux" is not the same, echo execution has ended, and Influxd for the service has been executed, if not in the background, then INFLUXD will not return after startup, Then the init process waits for the influxd to complete, causing the subsequent program to fail to execute.

This really pits me, when I wrote:

#!/usr/bin/python...influxdtelegraf

Found Influxd started successfully, Telegraf is not up. Later put Telegraf write in front can get up, but influxd again do not come to guess is this reason ~~~bingo.

Linux Setup boot entry two ways

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.