2

I'm trying to switch from cron to systemd for a pretty simple thing. I have a small bash script sync_org_git which basically cd-s into a specific folder, does some git manipulations. The git commands write some things to stdout (untracked files, feedback after commit etc) which is nothing out of the ordinary for git, but systemctl --user start sync-org-git.timer says job failed. Do I need to modify my script or the systemd files?

Here's the service and timer file:

❯ cat sync-org-git.service
[Unit]
Description=sync org to git


[Service]
ExecStart=/home/fbence/bin/sync_org_git

❯ cat sync-org-git.timer
[Unit]
Description=Sync org git timer
Requires=sync-org-git.service

[Timer]
OnBootSec=0min
OnCalendar=*:*:0/5
Unit=sync_org_git.service

[Install]
WantedBy=multi-user.target

UPDATE

Using ExecStart=-/home/fbence/bin/sync_org_git

results in sync-org-git.timer: Refusing to start, unit sync_org_git.service to trigger not loaded.

but I actually see the output of the shell script in the journal.

6
  • Do you always do a systemctl --user daemon-reload after editing the unit files? Commented Aug 12, 2022 at 11:49
  • yes (this is just to have a long enough comment) Commented Aug 12, 2022 at 12:08
  • 1
    You are using underlines in Unit= but the unit filename uses hyphens. Commented Aug 12, 2022 at 12:31
  • Wow, well that is embarrassing ... :D That was actually the problem ... The only mystery is then, how did output from the script still get triggered (or at least, why did I see it's output in the logs?). Commented Aug 12, 2022 at 13:28
  • 1
    Did you not have the Unit= line originally, as you don't need it anyway when the service has the same name (with .timer replaced by .service, of course). Commented Aug 12, 2022 at 14:12

1 Answer 1

0

If your command exits with a non-zero return code, then systemd takes this as a failure to run. You can either ignore the return code by adding a - prefix as in ExecStart=-/home/fbence/bin/sync_org_git, or you can add an extra line listing what return codes mean ok, eg:

SuccessExitStatus=0 1 7
3
  • That's exactly my problem, that exit code of my script is 0. At least when I run it manually it is 0, and if I run it via systemctl the printed output seems to be exactly the same, so that's why I don't understand what is going on. Commented Aug 12, 2022 at 11:20
  • See the update with -. Commented Aug 12, 2022 at 11:39
  • 1
    Tbh, this was not exactly my problem, but it did help, and considering you solved my problem in a comment, I'm going to accept this answer. Commented Aug 12, 2022 at 13:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.