在 Debian 9 (Stretch) 中啟用消失的 rc.local

在 Debian 9 (Stretch) 中啟用消失的 rc.local

Debian 9 (Stretch)預設不使用 rc.local, 所以會找不到/etc/rc.local 檔.
但是還是有辦法可以使用rc.local

首先自己先創造/etc/rc.local檔 :

# cat <<EOF >/etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0
EOF

設定可執行權限:

# chmod +x /etc/rc.local

然後啟用rc-local 這個服務即可

# systemctl start rc-local

觀察rc-local 這個服務是否已經啟動:

# systemctl status rc-local

● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
       └─debian.conf
   Active: active (exited) since Wed 2017-08-16 14:12:44 CST; 5s ago
  Process: 1256 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Aug 16 14:12:44 vmsrv systemd[1]: Starting /etc/rc.local Compatibility...
Aug 16 14:12:44 vmsrv systemd[1]: Started /etc/rc.local Compatibility.

參考資料: Where is rc.local in Debian 9 (Debian Stretch)

This entry was posted in Linux, shell script and tagged , . Bookmark the permalink.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *