简体   繁体   English

脚本没有在启动时运行,systemd ubuntu

[英]Script not running on start up, systemd ubuntu

I am currently attempting to start Luigid when my Ubuntu server turns on, I have tried several techniques including rc.local, cronjob(@reboot), upstart, systemd and none of them appear to be working. 我正在尝试启动Luigid,当我的Ubuntu服务器打开时,我尝试了几种技术,包括rc.local,cronjob(@reboot),upstart,systemd,但它们似乎都没有工作。

I should point out that the command runs fine if I do it manually, I just need it to run on startup. 我应该指出,如果我手动执行该命令运行正常,我只需要它在启动时运行。 At this point I really don't have any concern which way I get it to work so here are some of the things I've tried - 在这一点上,我真的没有任何关注我的工作方式,所以这里有一些我尝试过的东西 -

Cron: 克龙:

Used 用过的

sudo crontab -e

and entered 并进入

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

Systemd: Systemd:

I have a script in /usr/bin called luigid with the following contents, it is marked as executable, and I have tried it with and without "exit 0" fearing a proper exit code might be required - 我在/ usr / bin中有一个名为luigid的脚本,其中包含以下内容,它被标记为可执行文件,我已尝试使用和不使用“exit 0”,因为可能需要正确的退出代码 -

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

and a service file in /etc/systemd/system/ called luigid.service - 和/ etc / systemd / system /中的服务文件名为luigid.service -

[Unit]
Description=Luigid Service

[Service]
Type=forking
ExecStart=/usr/bin/luigid

[Install]
WantedBy=multi-user.target

I have tried forking(and specifying the PIDfile in both the service and in the lugid command, oneshot and simple as the types with no luck. 我已经尝试过分叉(并在服务和lugid命令中指定PID文件,somehot和simple作为没有运气的类型。

I have enabled the service using - 我使用了 - 启用了服务 -

systemctl enable luigid.service

It appears it attempts to start the service because checking the status using 它似乎尝试启动该服务,因为使用检查状态

systemctl status luigid.service

shows 节目

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'.

There must be something obvious I'm missing, it really can't be this hard to get a command to run on startup! 必须有一些明显我缺少的东西,在启动时运行命令真的不是很难!

Reviewing the startup options: Neither "rc.local" and "cron @reboot" will help you if the service crashes later, so they aren't ideal. 查看启动选项:如果服务稍后崩溃,“rc.local”和“cron @reboot”都不会帮助您,因此它们并不理想。 Since it appears you have a systemd-based system, then Upstart isn't really an option. 由于看起来你有一个基于systemd的系统,所以Upstart不是一个真正的选择。 systemd is a good option to focus on because it will not only start your process, but also restart it if it crashes. systemd是一个很好的选择,因为它不仅可以启动您的进程,还可以在崩溃时重新启动它。

I don't know what the right option for Type= is for this service, but it does matter. 我不知道Type=的正确选项对于这项服务是什么,但它确实很重要。 Check the docs for Type= in man systemd.service to determine which one is correct for your service. 检查文档中的Type= in man systemd.service以确定哪一个对您的服务是正确的。

Your wrapper script shouldn't be required. 不应该要求您的包装脚本。 You should be able to have an ExecStart= line like this: 您应该能够拥有这样的ExecStart=行:

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

I would also try removing the --background option and setting the Type= to simple if you haven't tried that combination. 我还尝试删除--background选项并将Type=设置为simple如果您还没有尝试过该组合。

If you can't get it to work, try get your daemon to provide more verbose logging about why it's not starting, or resort to adding /usr/bin/strace to the beginning of your ExecStart= line to get detailed logging of the system calls that the binary is making during startup. 如果你无法让它工作,请尝试让你的守护进程提供更详细的日志记录,说明它为什么没有启动,或者尝试将/usr/bin/straceExecStart=行的开头以获取系统的详细日志记录在启动期间调用二进制文件。 One of the final few calls could point to where it is hanging. 最后的几个电话之一可能指向它挂起的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM