0

I have a service on my Raspberry Pi which runs a bash file on boot. I recently updated the bash file (run.sh) but the service is not reflecting the update.

So far I have tried:

  • sudo systemctl disable/enable garden-zero.service

  • sudo systemtl stop/start garden-zero.service

  • sudo systemctl daemon-reload

Nothing has worked. The service is still not running the environment.py script I added.

Bash File (run.sh)

#!/bin/sh

# Sensors
/home/pi/apps/garden-zero/sensors/environment.py &
/home/pi/apps/garden-zero/sensors/soil-temperature.py &
/home/pi/apps/garden-zero/sensors/soil-moisture.py &

# Metrics
/home/pi/apps/garden-zero/metrics/heartbeat.py &

Service Config

[Unit]
Description=Garden Zero
After=network-online.target

[Service]
Type=forking
ExecStart=run.sh
WorkingDirectory=/home/pi/apps/garden-zero
StandardOutput=inherit
StandardError=inherit
Restart=always
User=gardenAdmin

[Install]
WantedBy=multi-user.target

Output when status is run

 garden-zero.service - Garden Zero
   Loaded: loaded (/etc/systemd/system/garden-zero.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2021-06-03 02:40:11 BST; 1h 23min ago
    Tasks: 7 (limit: 725)
   CGroup: /system.slice/garden-zero.service
           ├─406 python3 /home/pi/apps/garden-zero/sensors/soil-temperature.py
           ├─407 python3 /home/pi/apps/garden-zero/sensors/soil-moisture.py
           └─408 python3 /home/pi/apps/garden-zero/metrics/heartbeat.py

Jun 03 02:40:11 raspberrypi systemd[1]: Starting Garden Zero...
Jun 03 02:40:11 raspberrypi systemd[1]: Started Garden Zero.

I would expect to see /home/pi/apps/garden-zero/sensors/environment.py listed but its not
1
  • You should include some kind of logging in your code if you are running it in the background otherwise everything that happens with it will remain a mystery to you.
    – goldilocks
    Jun 3, 2021 at 16:52

1 Answer 1

2

The systemd WorkingDirectory= setting defines on which directory the service will be launched, same as when you use cd to change a directory when you're working in the shell.

That doesn't mean that all the other paths (including that from ExecStart=) will now be relative to it, so you still need to fully specify the path to your script in that directive:

ExecStart=/home/pi/apps/garden-zero/run.sh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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