centOS7添加開機啟動服務/執行腳本


centOS7添加開機啟動服務/執行腳本

1 開機啟動服務

 /etc/rc.d/rc.local  后追加shell腳本  



在centos7中添加開機自啟服務非常方便,只需要兩條命令(以Jenkins為例):

#設置jenkins服務為自啟動服務
systemctl enable jenkins.service 
#啟動jenkins服務
systemctl start jenkins.service
2 開機執行腳本

在centos7中增加腳本有兩種常用的方法:

修改/etc/rc.d/rc/local文件並修改配置
腳本放到/etc/rc.d/init.d目錄下並進行配置
以下示例以腳本autostart.sh為例:

#!/bin/bash
# description:開機自啟腳本
# 啟動tomcat
/usr/local/tomcat/bin/startup.sh 
2.1 修改/etc/rc.d/rc/local文件並修改配置

1、賦予自定義腳本可執行權限(/opt/script/autostart.sh是自定義腳本)

chmod +x /opt/script/autostart.sh 
2、打開/etc/rc.d/rc/local文件,在末尾增加如下內容

/opt/script/autostart.sh 
3、在centos7中,/etc/rc.d/rc.local的權限被降低了,所以需要執行如下命令賦予其可執行權限

chmod +x /etc/rc.d/rc.local
2.2 腳本放到/etc/rc.d/init.d目錄下並進行配置

1、將腳本移動到/etc/rc.d/init.d目錄下

mv /opt/script/autostart.sh /etc/rc.d/init.d
2、增加腳本的可執行權限

chmod +x /etc/rc.d/init.d/autostart.sh
3、添加腳本到開機自動啟動項目中

cd /etc/rc.d/init.d
chkconfig --add autostart.sh
chkconfig autostart.sh on

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM