Systemd 服务在启动时失败 [英] Systemd service failing on startup

查看:35
本文介绍了Systemd 服务在启动时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让 nodejs 服务器在启动时运行,所以我创建了以下 systemd 单元文件:

I'm trying to get a nodejs server to run on startup, so I created the following systemd unit file:

[Unit]
Description=TI SensorTag Communicator
After=network.target

[Service]
ExecStart=/usr/bin/node /home/pi/sensortag-comm/sensortag.js
User=root

[Install]
WantedBy=multi-user.target

我不确定我在这里做错了什么.它似乎在 nodejs 脚本开始之前就失败了,因为没有发生日志记录.我的脚本依赖于 mysql 5.5(我认为这是我遇到问题的地方).任何见解,甚至不同的解决方案将不胜感激.

I'm not sure what I'm doing wrong here. It seems to fail before the nodejs script even starts, as no logging occurs. My script is dependent on mysql 5.5 (I think this is where I'm running into an issue). Any insight, or even a different solution would be appreciated.

此外,一旦我登录系统,它就可以正常运行.

Also, it runs fine once I'm logged into the system.

更新

服务已启用,并且正在通过 journalctl 进行日志记录.我会在 7/11/16 更新结果.

The service is enabled, and is logging through journalctl. I'll update with the results on 7/11/16.

不确定为什么它第一次不起作用,但是在检查 journalctl 时,问题 100% 是 MySQL 没有启动.我再次将其更改为 After=MySQL.service 并且完美运行!

Not sure why it didn't work the first time, but upon checking journalctl the issue was 100% that MySQL hadn't started. I once again changed it to After=MySQL.service and it worked perfectly!

推荐答案

如果在 journalctl 的输出中根本没有提及该服务,这可能表明该服务不是 启用 在启动时启动.

If there is no mention of the service at all in the output of journalctl that could indicate that the service was not enabled to start at boot.

让您在下次启动测试之前运行 systemctl enable my-unit-name.

Make you run systemctl enable my-unit-name before your next boot test.

此外,由于您依赖于 MySQL 的启动和运行,您应该声明如下:After=mysql.service.确切的服务名称可能取决于您未说明的 Linux 发行版.

Also, since you depend on MySQL being up and running, you should declare that with something like: After=mysql.service. The exact service name may depend on your Linux distribution, which you didn't state.

添加 User=root 不会添加任何内容,因为系统单元在默认情况下将由 root 运行.

Adding User=root adds nothing, as system units would be run by root by default anyway.

当您说失败"时,您没有说明它是在启动时失败,还是通过 systemctl start my-unit-name 运行的测试失败.

When you said "it fails", you didn't specify whether it was failing at boot time, or with a test run by systemctl start my-unit-name.

尝试启动服务后,如果您运行 journalctl -u my-unit.name.service,应该会记录日志.

After attempting to start a service, there should be logging if you run journalctl -u my-unit.name.service.

您还可以考虑将 StandardOutput=journal 添加到您的单元文件中,以确保您也从正在运行的服务中捕获输出.

You might also consider adding StandardOutput=journal to your unit file to make sure you capture output from the service you are running as well.

这篇关于Systemd 服务在启动时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆