AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1086397
Accepted
Ahmad Ismail
Ahmad Ismail
Asked: 2018-10-24 04:58:08 +0800 CST2018-10-24 04:58:08 +0800 CST 2018-10-24 04:58:08 +0800 CST

启用 lsyncd 的服务在 PC 重新启动时不会自动启动 - 活动:不活动(死)

  • 772

我通过合并所有以前的编辑来超级简化了这个问题

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)重启后显示?

kde server kubuntu services systemd
  • 2 2 个回答
  • 2615 Views

2 个回答

  • Voted
  1. Best Answer
    WinEunuuchs2Unix
    2018-10-31T18:52:55+08:002018-10-31T18:52:55+08:00

    Systemd 可能与之前和之后的混淆,但我会改变:

    After=network.target remote-fs.target media-blueray-Data.mount media-blueray-WDRed.mount
    

    至:

    After=network.target remote-fs.target media-blueray-Data.mount media-blueray-WDRed.mount network.target multi-user.target
    

    基于这个答案。

    • 2
  2. Ahmad Ismail
    2018-11-01T05:21:37+08:002018-11-01T05:21:37+08:00

    在以下位置创建 lsyncd 配置文件(您也可以将其放在其他位置)/home/blueray/.config/lsyncd.conf.lua

    settings {
        logfile = "/media/blueray/WDRed/_LsyncLog/lsyncd.log",
        statusFile = "/media/blueray/WDRed/_LsyncLog/lsyncd-status.log",
        pidfile="/home/blueray/.config/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
    Requires=default.target
    After=default.target
    
    [Service]
    Type=forking
    ExecStart=/usr/bin/lsyncd /home/blueray/.config/lsyncd.conf.lua
    PIDFile=/home/ismail/.config/lsyncd.pid
    ExecReload=/bin/kill -HUP $MAINPID
    ExecStop=/bin/kill $MAINPID
    Restart=always
    RestartSec=10
    
    [Install]
    WantedBy=default.target
    

    调试步骤动机:

    由于这类问题困扰着互联网 -

    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服务(在启动时运行它),则需要部分。

    $ systemctl --user list-dependencies 
    
    default.target
    ● └─basic.target
    ●   ├─paths.target
    ●   ├─sockets.target
    ●   │ ├─dirmngr.socket
    ●   │ ├─gpg-agent-browser.socket
    ●   │ ├─gpg-agent-extra.socket
    ●   │ ├─gpg-agent-ssh.socket
    ●   │ └─gpg-agent.socket
    ●   └─timers.target
    
    $ systemd-analyze --user critical-chain
    
    default.target @12ms                                                                                                                                                                                                                                                           
    └─basic.target @12ms                                                                                                                                                                                                                                                           
      └─paths.target @12ms    
    

    Requires=如果需要,您可以After=在部分下方使用选定的目标[Unit]。

    使用启用服务systemctl --user enable lsyncd

    如果重新启动计算后,服务未运行。使用检查服务的状态systemctl --user status lsyncd

    如果您发现类似lsyncd Start request repeated too quickly.的错误

    RestartSec=下使用[Service]

    笔记:

    采用以秒为单位的无单位值,或时间跨度值,例如“5min 20s”。默认为 100 毫秒。

    你也可以使用类似的东西

    StartLimitInterval=10
    StartLimitBurst=1
    

    来解决这个问题。

    在单位文件发生任何变化后使用

    $ systemctl --user daemon-reload
    // Disabling before enabling helped me. But I do not think it is necessary.
    // $ systemctl --user disable lsyncd
    $ systemctl --user enable lsyncd
    

    PS:这是一个简短的调试指南。网上有很多关于这方面的文章。我的不完整(还有十几个命令可以提供帮助,即journalctl具有不同属性来读取日志)。但我希望它能帮助许多初学者使用systemd。

    • 0

相关问题

  • KATE 总是忘记我启用了 shell 插件

  • 如果在服务器机器上运行 Ubuntu 桌面版,性能损失是多少?

  • 将桌面版剥离为服务器版的最简单方法是什么?

  • 安装 XFCE 后如何返回 KDE 启动/登录?

  • 如何与无头服务器进行图形交互?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve