我想用来systemd
在启动时启动服务。但是我收到消息说该服务处于非活动状态(已死):
root@mdchost:/lib/systemd/system# systemctl status mdc_freespace_vldy_fusion_node.service
● mdc_freespace_vldy_fusion_node.service - MDC Freespace Vldy Fusion Node
Loaded: loaded (/lib/systemd/system/mdc_freespace_vldy_fusion_node.service; enabled; vendor preset:
Active: inactive (dead) since Sat 2018-08-04 01:06:48 BST; 5min ago
Process: 3841 ExecStartPost=/bin/bash /usr/bin/mdc/base/set_limit.sh FUSI mdc_freespace_vldy_fusion_
Process: 3838 ExecStart=/usr/bin/mdc/fusion/mdc_freespace_vldy_fusion_node (code=exited, status=0/SU
Process: 3090 ExecStartPre=/opt/x86/ros/kinetic/bin/rosparam load /etc/mdc/fusion/kinematics_dynamic
Process: 2266 ExecStartPre=/opt/x86/ros/kinetic/bin/rosparam load /etc/mdc/fusion/freespace_vldy_fus
Main PID: 3838 (code=exited, status=0/SUCCESS)
但是我可以通过执行命令让它手动启动:
systemctl restart mdc_freespace_vldy_fusion_node.service
现在服务的状态变为活动(运行):
root@mdchost:/lib/systemd/system# systemctl status mdc_freespace_vldy_fusion_node.service
● mdc_freespace_vldy_fusion_node.service - MDC Freespace Vldy Fusion Node
Loaded: loaded (/lib/systemd/system/mdc_freespace_vldy_fusion_node.service; enabled; vendor preset:
Active: active (running) since Sat 2018-08-04 01:29:31 BST; 1s ago
Process: 2065 ExecStartPost=/bin/bash /usr/bin/mdc/base/set_limit.sh FUSI mdc_freespace_vldy_fusion_
Process: 2017 ExecStartPre=/opt/x86/ros/kinetic/bin/rosparam load /etc/mdc/fusion/kinematics_dynamic
Process: 1991 ExecStartPre=/opt/x86/ros/kinetic/bin/rosparam load /etc/mdc/fusion/freespace_vldy_fus
Main PID: 2063 (mdc_freespace_v)
Tasks: 6
Memory: 3.5M
CPU: 469ms
CGroup: /system.slice/mdc_freespace_vldy_fusion_node.service
└─2063 /usr/bin/mdc/fusion/mdc_freespace_vldy_fusion_node
这是我的服务文件:
[Unit]
Description=My Node
Requires=start_roscore.service
After=start_roscore.service
[Service]
User=mdc
Group=mdc
Type=simple
KillMode=proces
Restart=on-failure
RestartSec=16
StartLimitInterval=0
EnvironmentFile=/usr/bin/mdc/base/env.cfg
EnvironmentFile=/usr/bin/mdc/ros/ros.cfg
ExecStartPre=/opt/x86/ros/kinetic/bin/rosparam load /etc/mdc/fusion/freespace_vldy_fusion_config.yaml
ExecStartPre=/opt/x86/ros/kinetic/bin/rosparam load /etc/mdc/fusion/kinematics_dynamics.yaml
ExecStart=/usr/bin/mdc/fusion/mdc_freespace_vldy_fusion_node
ExecReload=/usr/bin/mdc/fusion/mdc_freespace_vldy_fusion_node
ExecStartPost=/bin/bash /usr/bin/mdc/base/set_limit.sh FUSI mdc_freespace_vldy_fusion_node
看一看
journalctl -u mdc_freespace_vldy_fusion_node.service
。此服务以 0 退出。有一些关于早期启动状态的
/usr/bin/mdc/fusion/mdc_freespace_vldy_fusion_node
不喜欢的东西。