標籤:啟動命令 system higher 程式 使用者 rc.local
開機不啟動
在實際生產情境中,我們喜歡在安裝了一些軟體服務後,將軟體佈建為開機自啟動,設定為開機自啟動有兩種方法:
1) 設定為chkconfig,可以編寫指令碼,查看設定開機自啟動的命令 –add表示添加程式自啟動, --list表示查看。
以後的程式如果需要使用chkconfig開機自啟動,那麼需要在啟動程式中加入三行:
# chkconfig:2345 20 80
#description: Saves and restores system entropy pool for \
# higher quality random numbergeneration.
第一行中的20,80是啟動層級,不能與其他程式一樣,因此,需自訂設定。
2) 配置在/etc/rc.local檔案中。直接將軟體服務的啟動命令寫在rc.local檔案
注意:編輯完rc.local檔案後,一定要給rc.local檔案執行許可權,否則開機時不會執行rc.local檔案中指令碼命令
chmod+x /etc/rc.local
關於在rc.local檔案中指定使用者執行指令碼命令
使用su命令即可,命令格式:
su - username -c “your-cammand” ,如:
[[email protected] ~]$ cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemdservices or udev rules
# to run scripts during boot instead of using thisfile.
#
# In constrast to previous versions due to parallelexecution during boot
# this script will NOT be run after all otherservices.
#
# 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
/bin/systemctl start iptables.service
#startup mongodb
/bin/su - xiaoyao -c "/mnt/mongodb/bin/mongod --config/mnt/mongodb/bin/mongodb.conf"
注意:指定使用者執行的指令碼(程式)目錄,該使用者必須有管理該指令碼(程式)目錄(檔案)的許可權。
最好將該指令碼(程式)目錄的所有權給該使用者:
chown -R xiaoyao.xiaoyao /mnt/mongodb
Centos 7關於rc.local指令碼命令開機不執行及指定使用者啟動的解決方案