Linux (with Redhat as the template) to add boot scripts there are two methods, first to simple;
First, add in the/etc/rc.local
If you don't want to glue the script, or create a link or something,
The
Step1. First, modify the script so that all its modules can be executed when any directory is started;
Step2. Add a row at the end of/etc/rc.local to start the script with an absolute path;
Such as:
$ vim/etc/rc.local
#!/bin/sh
#
# This script is executed *after* all and the other init scripts.
# can put your own initialization stuff in here if you don ' t
# want to does the full Sys V style init stuff.
touch/var/lock/ SUBSYS/LOCAL
. /ETC/RC.D/RC.TUNE
/opt/pjt_test/test.pl
save and exit;
Restart the test, the script will be started after the other programs are started;
Second, theinit.d directory are executable programs, they are actually service scripts, written in a certain format, Linux at startup will automatically execute, similar to the services under Windows
Log in with root account, Vi/etc/rc.d/init.d/mystart, append the following content:
#!/bin/bash#chkconfig:2345 80 05-- Specify at which levels to perform, 0 generally refers to shutdown, 6 refers to reboot, others for normal startup. 80 priority for boot, 05 for off priority #description:mystart Serviceretval=0start () {--entry function to start the service echo-n "Mystart serive ..." cd/home/ Test1su test1-c "python/home/test1/test.py"}stop () {--Closes the entry function of the service echo "Mystart service is stoped ..."}case $ in--use case to For interactive operation start) start; stop) stop;; Esacexit $RETVAL |
3, run chmod +r/etc/rc.d/init.d/mystart, so that it can be directly executed4, run Chkconfig--add mystart, add the service to the configuration 5, run Chkconfig--list Mystart, you can view the status of the service process
example:
#!/bin/bash
#chkconfig: 2345 80 05--specify at which levels to execute, 0 generally refers to the shutdown, 6 refers to the restart, the other for normal start. 80 priority for startup, 05 for shutdown
#description: Mqtt service
Retval=0
Start () {
Echo-n "Mqtt serive ..."
cd/home/ DPF
Su dpf-c "./hwjc_udp_receive &"
}
Stop () {
echo "Mqtt service is stoped ..."
}
Case $ in
Start)
start
;;
Stop)
Stop
;;
Esac
Exit $RETVAL
3, run chmod +r/etc/rc.d/init.d/mqtt, so that it can be directly executed
4. Run Chkconfig--add mqtt to add the service to the configuration
5, running Chkconfig--list Mqtt, can view the status of the service process
You can restart the system,
See if C programs start automatically
Linux implementation boot-up script