%20%E3%81%AE%20etherwake%20%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%9F%E8%B5%B7%E5%8B%95%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88%E3%81%8C%E5%8B%95%E4%BD%9C%E3%81%97%E3%81%AA%E3%81%84.png)
私は、マジック パケットを送信するコマンドを使用して、bash スクリプトでマスターが起動したときにスレーブ マシンをリモートで起動しようとしていますetherwake
。両方の OS は Debian 8 です。完全なコードは次のとおりです。
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
3つの異なる方法で使用してみました:
ローカル
#!/bin/sh -e
#
# rc.local
/etc/init.d/etherwake
etherwake <MAC Address>
/usr/sbin/etherwake <MAC Address>
exit 0
/etc/rc.local
まったく運がありません。どちらかを手動で root として実行すると/etc/init.d/etherwake
、すべてうまくいきます。権限に問題があるのではないかと考えましたが、私が読んだ限りでは、スクリプトはすべて/etc/init.d
デフォルトで root として実行されます。何が間違っているのでしょうか?
前もって感謝します。
編集:
Debian 8 では sysvinit ではなく systemd が使用されると理解しています。すべてをセットアップすると、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