0

I have a service that runs a python script:

[Unit]
Description="Daily python service"

[Service]
WorkingDirectory=/home/ubuntu/python_project/
ExecStartPre=/bin/bash -c 'truncate -s 0 /var/log/project.log /var/log/project_error.log'
ExecStart=/home/ubuntu/.conda/envs/test/bin/python -u main.py
StandardOutput=append:/var/log/project.log
StandardError=append:/var/log/project_error.log

[Install]
WantedBy=multi-user.target

I want this to run daily at a specific time:

[Unit]
Description=Run service daily

[Timer]
OnCalendar=*-*-* 12:00:00
Persistent=true

[Install]
WantedBy=timers.target

When I reload the daemon, enable the timer, and start the timer, it runs the first day. But after the first day it stops running automatically, unless I manually stop the service.

Why is this happening? And how do I get around this?

0

1 Answer 1

0

Here's an example of how I do something similar. In this example, I call the service every hour, so adjust yours as necessary:

/etc/systemd/system/btrfsbk.service

[Unit]
Description=Create mirror of current state of all BTRFS snapshots

[Service]
Type=simple
ExecStart=/usr/local/sbin/btrfsbk

/etc/systemd/system/btrfsbk.timer

[Unit]
Description=Create mirror of current state of all BTRFS snapshots

[Timer]
Unit=btrfsbk.service
OnBootSec=15min
OnUnitActiveSec=60min
AccuracySec=1us
Persistent=True

[Install]
WantedBy=timers.target

Notice how I do not have an [Install] section in the .service file; there's no need to enable this as it will be activated by the timer.

For another example, check out the fstrim service/timer files.

2
  • Still when I check the status, the trigger field is N/A.
    – RudyGoburt
    Commented Apr 26 at 3:24
  • Status of what - the service or the timer? Please add the results of your findings to your question, please. Commented Apr 26 at 15:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .