1. Add self-start service after boot
It is very convenient to add the self-start service in centos7, only two commands are needed (take Jenkins as an example):
systemctl enable mariadb.service #设置服务为自启动服务
sysstemctl start mariadb.service #启动mariadb服务
Two, add boot scripts
There are two common ways to add scripts in centos7. Take the script autostart.sh as an example:
#!/bin/bash
# chkconfig: - 85 15
# description:开机自启脚本
/usr/local/tomcat/bin/startup.sh #启动tomcat
method one
1. Grant script executable permissions (/opt/script/autostart.sh is your script path)
chmod +x /opt/script/autostart.sh
2. Open the /etc/rc.d/rc.local file and add the following content at the end
/opt/script/autostart.sh
3. In centos7, the permissions of /etc/rc.d/rc.local have been reduced, so you need to execute the following commands to give it executable permissions
chmod +x /etc/rc.d/rc.local
The above methods have been verified on the centos7 system, and the centos version is 7.3
Method Two
1. Move the script to the /etc/rc.d/init.d directory
mv /opt/script/autostart.sh /etc/rc.d/init.d
2. Increase the executable permissions of the script
chmod +x /etc/rc.d/init.d/autostart.sh
3. Add scripts to the automatic startup project
cd /etc/rc.d/init.d
chkconfig --add autostart.sh
chkconfig autostart.sh on