%20%E4%B8%8A%E7%9A%84%E5%95%9F%E5%8B%95%E8%85%B3%E6%9C%AC%E8%88%87%20etherwake%20%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
當主機透過 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
寫完劇本後,我做了:
chmod 755 /etc/init.d/etherwake
update-rc.d etherwake defaults
- 透過重新啟動系統
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