Close

Test script as SystemD service

A project log for Solar powered 24hr timelapse photography

A project using a solar powered Raspberry pi to wake up at midday and take a photo, each day for a year

berniebernie 05/20/2025 at 14:350 Comments

Initial test script power.py loaded as a systemd service. This simply saves a datetime line to a file to show the Pi is waking up at midday each day.

Create a file :

/lib/systemd/system/power.service

containing the following (with paths adjusted for your own script location):

    [Unit]
    Description=Runs Timelapse power cycles
    After=multi-user.target

    [Service]
    Type=idle
    ExecStart=/usr/bin/python3 /home/bernard/git/timelapse/power.py

    WorkingDirectory=/home/bernard/git/timelapse
    Restart=on-failure

    # Connects standard output to /dev/null
    StandardOutput=null

    # Connects standard error to journal
    StandardError=journal

    [Install]
    WantedBy=multi-user.target

Then set permissions of the file

sudo chown root:root /lib/systemd/system/power.service

sudo chmod 644 /lib/systemd/system/power.service

Enable the service

sudo systemctl daemon-reload

sudo systemctl enable power.service

This starts /home/bernard/git/timelapse/power.py on boot up.

Useful functions to test the service:

sudo systemctl start power

sudo systemctl stop power

sudo systemctl restart power

sudo systemctl status power

sudo systemctl disable power

Display last lines of the journal

sudo journalctl -n

Display and continuously print the latest journal entries

sudo journalctl -f


Discussions