进一步阅读

进一步阅读

我在 Ubuntu 16.04 LTS 下使用 ddclient/DDNS 来更新我拥有的两个域(来自 NameCheap)具有 DNS 记录的 IP(这是有效的)。

但是,问题是,由于有两个域,我需要运行两个单独的 ddclient 实例。.service为了做到这一点,我已经开始编写两个文件:

/usr/lib/systemd/system/ddclient_website1.service

[Unit]
Description=DDNS client for website1.tld

[Service]
ExecStart=/usr/sbin/ddclient -file /etc/ddclient_website1.conf

[Install]
WantedBy=multi-user.target

/usr/lib/systemd/system/ddclient_website2.service

[Unit]
Description=DDNS client for website2.tld

[Service]
ExecStart=/usr/sbin/ddclient -file /etc/ddclient_website2.conf

[Install]
WantedBy=multi-user.target

使用 ExecStart 命令中指定的配置,如下所示:

/etc/ddclient_website1.conf

daemon=1800
use=web, web=dynamicdns.park-your-domain.com/getip
protocol=namecheap
server=dynamicdns.park-your-domain.com
login=domain_1.tld
password=first_ddns_password
server_name

/etc/ddclient_website2.conf

daemon=1800
use=web, web=dynamicdns.park-your-domain.com/getip
protocol=namecheap
server=dynamicdns.park-your-domain.com
login=domain_2.tld
password=second_ddns_password
server_name

使用systemctl enable ddclient_website1.service(与 website2 相同)产生:

Created symlink from /etc/systemd/system/multi-user.target.wants/ddclient_website1.service to /usr/lib/systemd/system/ddclient_website1.service.

systemctl start ddclient_website1.service不产生任何输出。

ps -ef | grep ddclient仅列出刚刚运行的 grep,并systemctl status ddclient_website1.service产生:

● ddclient_website1.service - DDNS client for website1.tld
   Loaded: loaded (/usr/lib/systemd/system/ddclient_website1.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sun 2016-12-18 15:34:23 EST; 39s ago
  Process: 2687 ExecStart=/usr/sbin/ddclient -file /etc/ddclient_website1.conf (code=exited, status=0/SUCCESS)
 Main PID: 2687 (code=exited, status=0/SUCCESS)

Dec 18 15:34:23 server_name systemd[1]: Started DDNS client for website1.tld.

重新启动不会带来任何积极的变化。

编辑:

将文件修改.service为安装 ddclient 期间创建的默认.service文件后,我现在可以开始服务(它们列在ps -ef | grep ddclient.

[Unit]
Description=DDNS client for website1.tld
After=network.target

[Service]
Type=forking
PIDFile=/var/run/ddclient_website1.pid
ExecStart=/usr/sbin/ddclient -file /etc/ddclient_website1.conf

[Install]
WantedBy=default.target

然而,运行 40-50 秒后,它们超时,说明它们需要访问的 PID 文件不存在(两个服务都有同样的问题):

● ddclient_website1.service - DDNS client for website1.tld
   Loaded: loaded (/usr/lib/systemd/system/ddclient_website1.service; enabled; vendor preset: enabled)
   Active: failed (Result: timeout) since Sun 2016-12-18 16:04:14 EST; 22s ago
  Process: 1347 ExecStart=/usr/sbin/ddclient -file /etc/ddclient_website1.conf (code=exited, status=0/SUCCESS)

Dec 18 16:02:44 server_name systemd[1]: Starting DDNS client for website1.tld...
Dec 18 16:02:44 server_name systemd[1]: ddclient_website1.service: PID file /var/run/ddclient_website1.pid not readable (yet?) after start: No such file or directory
Dec 18 16:04:14 server_name systemd[1]: ddclient_website1.service: Start operation timed out. Terminating.
Dec 18 16:04:14 server_name systemd[1]: Failed to start DDNS client for website1.tld.
Dec 18 16:04:14 server_name systemd[1]: ddclient_website1.service: Unit entered failed state.
Dec 18 16:04:14 server_name systemd[1]: ddclient_website1.service: Failed with result 'timeout'.

touch编辑ddclient_website1.pid(也适用于 website2)/var/run并取得了相同的结果。

答案1

[服务]
ExecStart=/usr/sbin/ddclient -文件 /etc/ddclient_website1.conf

使用INI 文件中的PIDFile和设置是错误的,程序的选项也是错误的。该计划(与许多计划一样)实际上并未实施相关的准备协议。Type=forking-pid

与许多其他软件一样,正确的操作方法是使用该程序的-foreground选项,根据其 doco,该选项自修订版 113 起就已具有。

进一步阅读

答案2

这可能有关,尝试将该[Install]部分更改为

[Install]
WantedBy=default.target

答案3

问题是我没有指定 ddclient 的缓存和 PID 文件的位置。

根据--help页面:

  -file path            : load configuration information from 'path' (default: /etc/ddclient.conf).
  -cache path           : record address used in 'path' (default: /var/cache/ddclient/ddclient.cache).
  -pid path             : record process id in 'path'.

我的ExecStart命令只指定了-file,而我还需要指定-cache-pid

这是我的工作 ddclient_website1.service:

[Unit]
Description=DDNS client for website1.tld
After=network.target

[Service]
Type=forking
PIDFile=/var/run/ddclient_website1.pid
ExecStart=/usr/sbin/ddclient -file /etc/ddclient_website1.conf -pid /var/run/ddclient_website1.pid -cache /var/cache/ddclient/ddclient_website1.cache

[Install]
WantedBy=default.target

您还可以在 ddclient 的配置文件中指定这些路径/etc/ddclient_website1.conf

daemon=1800
use=web, web=dynamicdns.park-your-domain.com/getip
protocol=namecheap
server=dynamicdns.park-your-domain.com
login=website1.tld
password=my_ddns_password
cache=/var/cache/ddclient/ddclient_website1.cache
pid=/var/run/ddclient_website1.pid
@

您现在应该能够运行systemctl enable ddclient_website1.servicesystemctl start ddclient_website1.service让 ddclient 开始工作。

相关内容