代码之家  ›  专栏  ›  技术社区  ›  CD-jS

启动时未运行脚本,systemd ubuntu

  •  3
  • CD-jS  · 技术社区  · 8 年前

    我应该指出,如果我手动执行命令,该命令运行良好,我只需要它在启动时运行。在这一点上,我真的不关心我的工作方式,所以这里有一些我尝试过的东西-

    克朗:

    习惯于

    sudo crontab -e
    

    进入

    @reboot luigid --background --logdir /home/myuser/luigilog
    

    系统D:

    我在/usr/bin中有一个名为luigid的脚本,其中包含以下内容,它被标记为可执行,我尝试过使用和不使用“退出0”,因为担心可能需要正确的退出代码-

    #!/bin/sh
    exec luigid --background --logdir /home/myuser/luigilog
    

    以及/etc/systemd/system/中名为luigid的服务文件。服务-

    [Unit]
    Description=Luigid Service
    
    [Service]
    Type=forking
    ExecStart=/usr/bin/luigid
    
    [Install]
    WantedBy=multi-user.target
    

    我已经尝试过分叉(并在服务和lugid命令中指定了PIDfile),一次成功,而且简单,就像类型一样。

    systemctl enable luigid.service
    

    它似乎试图启动服务,因为正在使用检查状态

    systemctl status luigid.service

    luigid.service - Luigid Service
       Loaded: loaded (/etc/systemd/system/luigid.service; enabled; vendor preset: enabled)
       Active: failed (Result: timeout) since Mon 2016-10-10 15:18:00 UTC; 18min ago
    
    Oct 10 15:16:29 Analytics systemd[1]: Starting Luigid Service...
    Oct 10 15:18:00 Analytics systemd[1]: luigid.service: Start operation timed out. Terminating.
    Oct 10 15:18:00 Analytics systemd[1]: Failed to start Luigid Service.
    Oct 10 15:18:00 Analytics systemd[1]: luigid.service: Unit entered failed state.
    Oct 10 15:18:00 Analytics systemd[1]: luigid.service: Failed with result 'timeout'.
    

    肯定有一些明显的东西我遗漏了,在启动时运行命令真的不会这么难!

    1 回复  |  直到 8 年前
        1
  •  4
  •   Mark Stosberg    8 年前

    查看启动选项:“rc.local”和“cron@reboot”都不会在服务稍后崩溃时帮助您,因此它们并不理想。因为看起来您有一个基于systemd的系统,所以Upstart实际上不是一个选项。 systemd 是一个很好的选择,因为它不仅会启动您的进程,而且会在崩溃时重新启动它。

    我不知道什么是正确的选择 Type= 类型= 在里面 man systemd.service 以确定哪一个适合您的服务。

    不需要包装器脚本。你应该能够有一个 ExecStart= 像这样的线:

    ExecStart=/usr/bin/luigid --background --logdir /home/myuser/luigilog
    

    --background 选项并设置 类型= simple

    如果您无法让它工作,请尝试让守护进程提供更多详细的日志记录,说明为什么它不启动,或者尝试添加 /usr/bin/strace 到你的开始 执行开始= 行以获取二进制文件在启动期间进行的系统调用的详细日志记录。最后几个电话中的一个可能会指出它挂在哪里。