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

相关内容