2

I have a Debian stretch on RPI. I need to start a custom service on boot up.

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

Service is enabled, but shows up as inactive

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

Checking:

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

-- shows up nothing

If I start it manually from console, it works fine:

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.

Here are the contents of the service file:

[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

I have a small shell script to reset the GPIO pin, before the lora_pkt_fwd is launched. Here are the permissions for both files:

-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

Regarding the settings, have tried already:

  1. put "bash" for shell script - ExecStartPre=bash /home/pi/packet_forwarder/lora_pkt_fwd/reset_lgw.sh start
  2. Tried combinations of After=network.target, Before=network-online.target, Wants=network-online.target in [Unit] section
  3. Tried Type=simple and forking in [Service] section
  4. Tries disable/enable the service and daemon-reload (just in case)

I could get this done with cron task or something , but I want to do it right.

6
  • Did you run systemctl enable lora-packet-forwarder.service?
    – derobert
    Jul 5, 2019 at 15:01
  • 1
    I'm 99% guessing that the service has a dependency that hasn't yet been fulfilled during boot but is fulfilled after boot.
    – user2267
    Jul 5, 2019 at 19:39
  • derobert, yes I did already
    – Sergi
    Jul 6, 2019 at 1:23
  • @barrycarter, exactly, that's why (I assume) I tried these params "After=network.target, Before=network-online.target, Wants=network-online.target " hoping that service might be failing due to absence of the network connection. I wonder if there is a debug switch so I can get a more verbose reason/log?
    – Sergi
    Jul 6, 2019 at 1:28
  • Please include the output of systemctl status lora-packet-forwarder.service right after bootup, once systemctl list-jobs is already empty. Aug 31, 2019 at 16:10

1 Answer 1

0

Anyone looking here for the correct file, here is mine working.

[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  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.