centos7之添加開機啟動服務/腳本
阿新 • • 發佈:2018-03-18
gpo ast oca blog 自動啟動 udev 開機啟動腳本 centos init
一、添加開機啟動腳本
#!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run ‘chmod +x /etc/rc.d/rc.local‘ to ensure # that this script will be executed during boot. touch /var/lock/subsys/local
#添加開機啟動inotify.sh腳本
/root/inotify.sh
方法一
註意、服務也可以使用下面方法設置開機啟動,如追加rc.local文件追加/usr/bin/rsync --daemon就是開啟啟動rsync服務
1、首先,腳本具有可執行權限
chmod 755 inotify.sh
2、然後將腳本存放的絕對路徑+腳本全名追加到/etc/rc.d/rc.local文件最後
/root/inotify.sh
3、在centos7中,/etc/rc.d/rc.local的權限被降低了,所以需要執行如下命令賦予其可執行權限
在centos7中,/etc/rc.d/rc.local的權限被降低了,所以需要執行如下命令賦予其可執行權限
方法二
1、將腳本移動到/etc/rc.d/init.d目錄下
mv /opt/script/inotify.sh /etc/rc.d/init.d
2、增加腳本的可執行權限
chmod +x /etc/rc.d/init.d/inotify.sh
3、添加腳本到開機自動啟動項目中
cd /etc/rc.d/init.d chkconfig --add inotify.sh chkconfig inotify.sh
註意!
你直接把你的平時寫的加的腳本這樣chkconfig --add 肯定是要報service inotify.sh does not support chkconfig 錯誤的,不過你只需要在#!/bin/bash下面加上如下內容就行。
#chkconfig: 345 88 14
centos7之添加開機啟動服務/腳本