Debian 8 (Jessie) 上的啟動腳本與 etherwake 不起作用

Debian 8 (Jessie) 上的啟動腳本與 etherwake 不起作用

當主機透過 bash 腳本啟動時,我嘗試使用etherwake發送魔法資料包的命令遠端喚醒從機。兩個作業系統都是Debian 8。

/etc/init.d/etherwake

#!/bin/sh
#/etc/init.d/etherwake

### BEGIN INIT INFO
# Provides: etherwake
# Required-Start: $all
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start etherwake at boot time
# Description: Enable service provided by etherwake.
### END INIT INFO

ETHERWAKE=/usr/sbin/etherwake

case "$1" in

        start)
                echo  "Booting slaves through etherwake..."
                $ETHERWAKE <MAC Address>
                echo  "Finished booting all slaves."
                ;;

        stop)
                echo "Stop not implemented. Doing nothing"
                ;;

        restart|force-reload)
                $0 stop
                sleep 10
                $0 start
                ;;

        *)
                echo "Usage: /etc/init.d/etherwake {start}"
                exit 1
                ;;
esac

exit 0

寫完劇本後,我做了:

  1. chmod 755 /etc/init.d/etherwake
  2. update-rc.d etherwake defaults
  3. 透過重新啟動系統shutdown -r now

我還嘗試過/etc/rc.local以三種不同的方式使用:

/etc/rc.local

#!/bin/sh -e
#
# rc.local

/etc/init.d/etherwake
etherwake <MAC Address>
/usr/sbin/etherwake <MAC Address>
exit 0

沒有任何運氣。當我以 root 身份運行/etc/rc.local/etc/init.d/etherwake手動運行時,一切都運行良好。我認為這可能是具有權限的問題,但據我閱讀/etc/init.d默認情況下以 root 身份運行的任何腳本。我究竟做錯了什麼?

提前致謝。


編輯:

我了解 Debian 8 使用 systemd 而不是 sysvinit。設定完一切後systemctl -l status etherwake.service給我:

● etherwake.service - Etherwake magic packet service
   Loaded: loaded (/etc/systemd/system/etherwake.service; enabled)
   Active: inactive (dead) since Fri 2016-09-30 16:30:56 BRT; 1min 33s ago
  Process: 824 ExecStart=/etc/init.d/etherwake start (code=exited, status=0/SUCCESS)
 Main PID: 824 (code=exited, status=0/SUCCESS)

Sep 30 16:30:56 hostname etherwake[824]: Booting slaves through etherwake...
Sep 30 16:30:56 hostname etherwake[824]: Finished booting all slaves.

並且/etc/systemd/system/etherwake.service是:

[Unit]
Description=Etherwake magic packet service
Wants=network-online.target
After=syslog.service network.target network-online.target

[Service]
ExecStart=/etc/init.d/etherwake start

[Install]
WantedBy=default.target

我注意到的另一件事是跑步systemctl restart etherwake有一種魅力。

答案1

問題是這update-rc.d etherwake defaults可能行不通。嘗試透過 啟用服務systemctl,運行:

systemctl enable etherwake

相關內容