我已经安装了非ip动态ddns,下面是指南:https://www.noip.com/support/knowledgebase/installing-the-linux-dynamic-update-client/。
我让服务通过了
sudo /usr/local/bin/noip2但是,我希望服务在引导时启动,我尝试在/etc/init.d/noip2.sh中添加以下脚本
#######################################################
#! /bin/sh
# . /etc/rc.d/init.d/functions # uncomment/modify for your killproc
case "$1" in
start)
echo "Starting noip2."
/usr/local/bin/noip2
;;
stop)
echo -n "Shutting down noip2."
killproc -TERM /usr/local/bin/noip2
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
#######################################################其次是:
sudo chmod +x /etc/init.d/noip2.sh
sudo update-rc.d noip2.sh defaults现在我应该可以从
sudo service noip2 start但我不是。当我运行journalctl -xe时,我得到以下信息:
-- Unit noip2.service has begun starting up.
Nov 03 12:36:11 media systemd[3111]: noip2.service: Failed to execute command: Exec format error
Nov 03 12:36:11 media systemd[3111]: noip2.service: Failed at step EXEC spawning /etc/init.d/noip2.sh: Exec format error
-- Subject: Process /etc/init.d/noip2.sh could not be executed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The process /etc/init.d/noip2.sh could not be executed and failed.
--
-- The error number returned by this process is 8.
Nov 03 12:36:11 media systemd[1]: noip2.service: Control process exited, code=exited status=203
Nov 03 12:36:11 media systemd[1]: noip2.service: Failed with result 'exit-code'.
Nov 03 12:36:11 media systemd[1]: Failed to start noip2.service.
-- Subject: Unit noip2.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support为用户PerDuck更新的信息:我得到以下错误尝试您的解决方案.*(试图添加
RestartSec=30至少它现在一直在尝试,但它仍然没有开始。我仍然可以从sudo /usr/local/bin/noip2开始
错误:
Nov 03 23:26:42 media systemd[1]: noip2.service: Service hold-off time over, scheduling restart.
Nov 03 23:26:42 media systemd[1]: noip2.service: Scheduled restart job, restart counter is at 5.
Nov 03 23:26:42 media systemd[1]: Stopped noip2 service.
Nov 03 23:26:42 media systemd[1]: noip2.service: Start request repeated too quickly.
Nov 03 23:26:42 media systemd[1]: noip2.service: Failed with result 'start-limit-hit'.
Nov 03 23:26:42 media systemd[1]: Failed to start noip2 service.发布于 2018-11-03 19:08:51
自从Ubuntu15.04以来,控制后台进程(还有更多的)的标准方法是systemd。我建议从init.d脚本切换到systemd单元:
创建具有以下内容的文件/etc/systemd/system/noip2.service (并删除init.d脚本):
[Unit]
Description=noip2 service
[Service]
Type=forking
ExecStart=/usr/local/bin/noip2
Restart=always
[Install]
WantedBy=default.target然后发布
sudo systemctl daemon-reload要使systemd知道新的单元(systemd缓存单元文件,此命令使systemd重新考虑其缓存)。
现在,您可以尝试启动和停止您的单元并查看其状态:
sudo systemctl status noip2
sudo systemctl start noip2
sudo systemctl status noip2
sudo systemctl stop noip2
sudo systemctl status noip2要在启动时启动该单元,需要启用它:
sudo systemctl enable noip2若要在启动时禁用自动启动,必须禁用该单元:
sudo systemctl disable noip2大多数情况下,五个命令足以控制一个单位的行为:
systemctl start $unit # starts a unit NOW
systemctl stop $unit # stops a unit NOW
systemctl status $unit # shows status
systemctl enable $unit # starts a unit at boot time (but not NOW)
systemctl disable $unit # stops autostart (but doesn't stop the unit NOW)您还可以启用“自动启动”并立即启动该单元,或者禁用“自动启动”并立即停止:
systemctl enable --now $unit # enable and start in one go
systemctl disable --now $unit # disable and stop in one go一些研究显示,noip2作为守护进程运行,即启动它时,它会创建另一个在后台运行的进程(所谓的分叉),前台进程将立即返回(退出)。这就是init.d脚本和systemd单元失败的原因:他们启动noip2只是为了看到它立即退出。因此,systemd试图一次又一次地重新启动它,但没有结果。(默认情况下,systemd在放弃进程并使其处于失败状态之前,最多在10秒内重新启动进程5次。)
要告诉系统,该单元是分叉式的,添加行
Type=forking到[Service]部分,正如我刚才在上面的片段中所做的那样。这告诉systemd预期主进程会立即返回,但会看到noip2生成(分叉)的进程。
https://askubuntu.com/questions/1089704
复制相似问题