systemctl 自定义服务不会在启动时启动,但可以手动启动

systemctl 自定义服务不会在启动时启动,但可以手动启动

我在 RPI 上有 Debian 延伸。我需要在启动时启动自定义服务。

/lib/systemd/system/lora-packet-forwarder.service

服务已启用,但显示为非活动状态

lora-packet-forwarder.service - LoRa Packet Forwarder
   Loaded: loaded (/lib/systemd/system/lora-packet-forwarder.service; enabled; vendor preset: enabled)
   Active: inactive (dead)

检查:

sudo journalctl -f -u lora-packet-forwarder.service 

--什么也没显示

如果我从控制台手动启动它,它工作正常:

sudo systemctl start lora-packet-forwarder.service

lora-packet-forwarder.service - LoRa Packet Forwarder
   Loaded: loaded (/lib/systemd/system/lora-packet-forwarder.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-07-05 15:01:48 BST; 3s ago
  Process: 554 ExecStartPre=/home/pi/lora_gateway/reset_lgw.sh start (code=exited, status=0/SUCCESS)
 Main PID: 570 (lora_pkt_fwd)
   Memory: 568.0K
   CGroup: /system.slice/lora-packet-forwarder.service
           └─570 /home/pi/packet_forwarder/lora_pkt_fwd/lora_pkt_fwd

Jul 05 15:01:47 raspberrypi systemd[1]: Starting LoRa Packet Forwarder...
Jul 05 15:01:47 raspberrypi reset_lgw.sh[554]: Accessing concentrator reset pin through GPIO25...
Jul 05 15:01:48 raspberrypi systemd[1]: Started LoRa Packet Forwarder.

以下是服务文件的内容:

[Unit]
Description=LoRa Packet Forwarder

[Service]
WorkingDirectory=/home/pi/packet_forwarder/lora_pkt_fwd
ExecStartPre=/home/pi/packet_forwarder/lora_pkt_fwd/reset_lgw.sh start
ExecStart=/home/pi/packet_forwarder/lora_pkt_fwd/lora_pkt_fwd


[Install]
WantedBy=multi-user.target

在启动 lora_pkt_fwd 之前,我有一个小的 shell 脚本来重置 GPIO 引脚。以下是这两个文件的权限:

-rwxr-xr-x 1 pi pi  1485 Jul  3 21:38 reset_lgw.sh
-rwxr-xr-x 1 pi pi 144680 Jul  3 20:17 lora_pkt_fwd

关于设置,已经尝试过:

  1. 将“bash”作为 shell 脚本 -ExecStartPre=bash /home/pi/packet_forwarder/lora_pkt_fwd/reset_lgw.sh start
  2. 在 [Unit] 部分中尝试组合 After=network.target、Before=network-online.target、Wants=network-online.target
  3. 尝试 Type=simple 并在 [Service] 部分分叉
  4. 尝试禁用/启用服务和守护程序重新加载(以防万一)

我可以通过 cron 任务或其他东西来完成这件事,但我想把它做好。

答案1

任何人在这里寻找正确的文件,这是我的工作。

[Unit]  
Description=Packet forwarder for LORA-Helium  
After=network.target  
StartLimitIntervalSec=0  

[Service]  
Type=simple  
Restart=always  
RestartSec=1  
StartLimitAction=reboot  
User=pi  
WorkingDirectory=/home/pi/sx1302_hal/packet_forwarder/  
ExecStartPre=bash /home/pi/sx1302_hal/packet_forwarder/reset_lgw.sh start  
ExecStart=/home/pi/sx1302_hal/packet_forwarder/lora_pkt_fwd -c  /home/pi/sx1302_hal/packet_forwarder/global_conf.json  

[Install]  
WantedBy=multi-user.target  

相关内容