Add script to Linux boot

Time:2020-11-7

New update, edit / etc / RC. D directly/ rc.local You don’t need to create a new one

vim /etc/rc.d/rc.local

Using chkconfig

  • Write a script first
#!/bin/sh
#chkconfig:2345 80 90
#decription:autostart
nohup ~/frpc_linux_amd64 -t 7693dddbc9cc1413 -s 32 # mysql

! / bin / SH is the beginning of the shell script

chkconfig:2345 80 90 is to set the starting priority. First of all, you need to start Linux under Baidu. The script here means: the script should be started in Level 2, 3, 4 and 5. Its start priority should be 20, and its stop priority should be 80. If this line has no or no problem, it will give the default priority

D ecription:autostart Is the script description, does not affect the execution, not necessary

Nohup XXX is a command that I need to execute. Here, the file path must be the absolute path starting from the root directory. It is better not to find it

Move it to the / etc / RC. D / init. D directory

mv sf_ssh_frp.sh /etc/rc.d/init.d/sf_ssh_frp.sh

Then you have to give permission, otherwise it can’t be executed

chmod +x /etc/rc.d/init.d/sf_ssh_frp.sh

After that, use chkconfig to add boot

chkconfig --add sf_ssh_frp.sh

Chkconfig command:

Chkconfig -- add httpd ා add a service so that the chkconfig directive manages it
Chkconfig httpd on ා set the startup to run the service. The default is to set the 2345 level boot running service
Chkconfig -- list ා lists all services managed by chkconfig
Chkconfig -- add httpd ා add the specified service and let the chkconfig instruction manage it
Chkconfig -- del httpd ා removes the specified service and no longer allows the chkconfig instruction to manage it
Chkconfig httpd on ා to set the boot running service, you need to execute -- add before executing the command
Chkconfig httpd off ා to set whether the service does not run after startup, you need to execute -- add first to execute the command
Chkconfig -- level 35 httpd on ා set the service to run at Level 3 and level 5. The default is to set 2345 level to start running service
Chkconfig -- list ා level 0: shutdown
Atop 0: off 1: off 2: off 3: off 4: off 5: off 6: off ා level 1: single user mode / rescue mode
Auditd 0: off 1: off 2: off 3: off 4: on 5: off 6: off ා Level 2: multi user command line mode without network connection
Crond 0: off 1: off 2: on 3: on 4: on 5: on 6: off ᦇ Level 3: multi user command line mode with network connection
Ipset 0: off 1: off 2: on 3: on 4: on 5: on 6: off ᦇ level 4: not available
Iptables 0: off 1: off 2: off 3: off 4: on 5: off 6: off ා level 5: multi user mode with graphical interface
MySQL 0: off 1: off 2: on 3: on 4: on 5: on 6: off level 6: restart