Unison systemd 服务退出,状态代码为 3

Unison systemd 服务退出,状态代码为 3

我正在尝试使用以下文件为 unison 创建一个 systemd 服务unison.system

[Unit]
Description=Unison Sync
After=network.target

[Service]
ExecStart=/home/adamfg/bin/unison default
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
Type=simple
User=root
Environment=HOME=/home/adamfg/

[Install]
WantedBy=multi-user.target
Alias=unison.service

这是我的default.prf文件,位于/home/adamfg/.unison

root = /home/adamfg/workplace
root = ssh://[email protected]//home/adamfg/workplace

{Some Ignore Rules}

ignorecase = false
repeat = watch
log = true
logfile = /home/adamfg/.unison/unison.log
backup = Name *
maxbackups = 5
retry = 1
auto = true
batch = true
confirmbigdeletes = true
times = true
prefer = newer
terse = true
contactquietly = true
silent = true

如果我运行/home/adamfg/bin/unison defaultunison,它就会启动并继续正常运行。

但是,当我尝试使用 unison 运行systemctl start unison.service,然后使用查询状态时,systemctl status unison.service我得到以下结果:

unison.service - Unison Sync
   Loaded: loaded (/etc/systemd/system/unison.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2019-10-07 09:14:25 IST; 884ms ago
  Process: 14607 ExecStart=/home/adamfg/bin/unison default (code=exited, status=3)
Main PID: 14607 (code=exited, status=3)

我该如何修复这个问题以便能够将 unison 作为 systemd 服务运行?

答案1

问题是,unison 在作为服务运行时无法确定 ssh 私钥文件的位置,但如果您从命令行运行,它会自动为您的用户使用默认文件。

为了解决这个问题,我在文件中添加了以下行default.prf

sshargs= -oIdentityFile=/path/tos/ssh/key/id_rsa

答案2

两台机器上的锁阻止了同步启动。删除两个锁有助于解决问题。

unison -ui text
Fatal error: Warning: the archives are locked.
If no other instance of unison is running, the locks should be removed.
The file <file_URI> on host <hostname> should be deleted
The file <file_URI> on host <hostname> should be deleted
Please delete lock files as appropriate and try again.

相关内容