Making scripts restart, start on power-on and so on

Buried in another discussion, I asked what would be the recommended way to make my data collection script start up automatically, restart on crash and so on. I’m not sure there is one, so I’ve decided to use systemd to do it. I created a mymelcloud.service file containing the command that starts the data collector (ExecStart below) and some details about what it needs (a network to connect to the cloud, somewhere to write its logs):

[Unit]
Description=My Melcloud client
After=var-log.mount network-online.target

[Service]
Type=simple
Restart=always
RestartSec=30
User=pi
ExecStart=/home/pi/melcloud/mymelcloud-feed-launch.sh

[Install]
WantedBy=multi-user.target

Then that’s loaded in with sudo systemctl enable /home/pi/melcloud/mymelcloud.service and away it goes! If you need to edit the .service file, then you need to run systemctl daemon-reload for it to react to the changes.

Can anyone see what I’ve done wrong? :wink:

That’s about how it is done for other scripts :slight_smile:

Check out the “Service-Runner” that is part of EmonCMS for example.