我通过合并所有以前的编辑来超级简化了这个问题
lsyncd 配置文件/etc/lsyncd/lsyncd.conf.lua
settings {
logfile = "/media/blueray/WDRed/_LsyncLog/lsyncd.log",
statusFile = "/media/blueray/WDRed/_LsyncLog/lsyncd-status.log",
pidfile="/media/blueray/WDRed/_LsyncLog/lsyncd.pid",
statusInterval = 5,
nodaemon = false,
}
sync {
default.rsync,
source = "/media/blueray/Data/",
target = "/media/blueray/WDRed/_LsyncBackup/",
delay = 0,
exclude = { "/_RedoBackup" },
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
_extra = { "--backup-dir=/media/blueray/WDRed/_LsyncDeletedBackup/" },
}
}
lsyncd 服务文件/home/blueray/.config/systemd/user/lsyncd.service
[Unit]
Description=Live Syncing (Mirror) Daemon
After=network.target remote-fs.target media-blueray-Data.mount media-blueray-WDRed.mount
Wants=media-blueray-Data.mount media-blueray-WDRed.mount
Requires=media-blueray-Data.mount media-blueray-WDRed.mount
[Service]
Type=forking
ExecStart=/usr/bin/lsyncd /etc/lsyncd/lsyncd.conf.lua
PIDFile=/media/blueray/WDRed/_LsyncLog/lsyncd.pid
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill $MAINPID
Restart=always
[Install]
WantedBy=multi-user.target
重启前
blueray@blueray-i58600K:~$ systemctl --user start lsyncd
blueray@blueray-i58600K:~$ systemctl --user enable lsyncd
blueray@blueray-i58600K:~$ systemctl --user status lsyncd
● lsyncd.service - Live Syncing (Mirror) Daemon
Loaded: loaded (/home/blueray/.config/systemd/user/lsyncd.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2018-10-29 11:58:22 +06; 11s ago
Main PID: 1921 (lsyncd)
CGroup: /user.slice/user-1000.slice/[email protected]/lsyncd.service
└─1921 /usr/bin/lsyncd /etc/lsyncd/lsyncd.conf.lua
Oct 29 11:58:22 blueray-i58600K systemd[916]: Starting Live Syncing (Mirror) Daemon...
Oct 29 11:58:22 blueray-i58600K systemd[916]: Started Live Syncing (Mirror) Daemon.
blueray@blueray-i58600K:~$
重启后
blueray@blueray-i58600K:~$ systemctl --user status lsyncd
● lsyncd.service - Live Syncing (Mirror) Daemon
Loaded: loaded (/home/blueray/.config/systemd/user/lsyncd.service; enabled; vendor preset: enabled)
Active: inactive (dead)
blueray@blueray-i58600K:~$
如您所见,如果我发出命令,此服务运行良好systemctl --user start lsyncd
为什么虽然我给出了命令但它没有自动启动systemctl --user enable lsyncd
。为什么Active: inactive (dead)
重启后显示?
Systemd 可能与之前和之后的混淆,但我会改变:
至:
基于这个答案。
在以下位置创建 lsyncd 配置文件(您也可以将其放在其他位置)
/home/blueray/.config/lsyncd.conf.lua
在以下位置创建 lsyncd 服务文件
/home/blueray/.config/systemd/user/lsyncd.service
调试步骤动机:
由于这类问题困扰着互联网 -
https://superuser.com/questions/955922/enabled-systemd-unit-does-not-start-at-boot
https://unix.stackexchange.com/questions/237795/lsyncd-wont-start-at-startup
https://unix.stackexchange.com/questions/374638/why-x0vncserver-is-not-starting-at-boot?rq=1
https://unix.stackexchange.com/questions/98033/service-not-starting-at-boot
https://unix.stackexchange.com/questions/282174/squid-systemd-service-not-run-at-boot
https://unix.stackexchange.com/questions/255788/what-is-wrong-with-my-systemd-unit-file
https://unix.stackexchange.com/questions/137028/why-is-my-systemd-unit-loaded-but-inactive-dead
https://unix.stackexchange.com/questions/376038/systemd-why-is-this-service-inactive-dead/376043
https://unix.stackexchange.com/questions/159174/differences-between-inactive-vs-disabled-and-active-vs-enabled-services
https://unix.stackexchange.com/questions/376038/systemd-why-is-this-service-inactive-dead
https://unix.stackexchange.com/questions/251211/why-doesnt-my-systemd-user-unit-start-at-boot
还有很多。
我还想添加帮助我解决问题的调试步骤。
调试步骤:
第 1 步是尽量保持简单。
后添加
media-blueray-Data.mount
等media-blueray-WDRed.mount
After=, Wants=, Requires=
等使事情变得复杂。对于用户服务,使用
systemctl --user list-dependencies
和/或systemd-analyze --user critical-chain
找出您想要在WantedBy=
以下[Install]
部分中添加的内容 -注意:
[Install]
如果您想要enable
服务(在启动时运行它),则需要部分。Requires=
如果需要,您可以After=
在部分下方使用选定的目标[Unit]
。使用启用服务
systemctl --user enable lsyncd
如果重新启动计算后,服务未运行。使用检查服务的状态
systemctl --user status lsyncd
如果您发现类似
lsyncd Start request repeated too quickly.
的错误RestartSec=
下使用[Service]
笔记:
你也可以使用类似的东西
来解决这个问题。
在单位文件发生任何变化后使用
PS:这是一个简短的调试指南。网上有很多关于这方面的文章。我的不完整(还有十几个命令可以提供帮助,即
journalctl
具有不同属性来读取日志)。但我希望它能帮助许多初学者使用systemd。