準備工作
普通用戶ks加入了sudoer ,免密
用ks登錄系統
開啓 rc-local服務
sudo systemctl enable rc-local
修改rc.local
sudo chmod +x /etc/rc.d/rc.local
sudo vi /etc/rc.d/rc.local
rc.local內容如下
#!/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
su - ks -s "/ks/start_bfs_all.sh"
每次系統啓動都會toch /var/lock/subsys/local ,這個文件的修改時間也就是系統最後啓動時間,後面我們加了一行我們要啓動腳本 。
- ks
表示要切換到ks用戶下執行-s
表示要執行的腳本文件,要用絕對路徑
執行的腳本要有執行權限
sudo chmod +x /ks/start_bfs_all.sh
示例: start_bfs_all.sh腳本內容如下,這裏腳本又嵌套了腳本
cd /aos/ks/9324 && "./start.sh"
cd /aos/ks/afs_bin &&"./start.sh"
cd /ks/9210ED00-09 && "./start.sh"
cd /ks/9324FF00-39 && "./start.sh"
cd /ks/pn/pnc && "./start.sh
測試自啓動:啓動rc-local或者重啓系統
su root
sudo systemctl start rc-local
or
sudo systemctl reboot
檢查你的程序是否啓動
問題排查: 腳本執行出錯?
journalctl -e -u rc-local.service
systemctl status rc-local
sudo cat /var/log/syslog | grep -i rc.local