You are not logged in.

#1 2014-10-15 14:00:47

alex404
Member
Registered: 2009-12-03
Posts: 51

[SOLVED] script.service activated by script.timer behaves unusually

Hi there,

So I've written a little program for managing daily backups in Haskell, which I call 'tarsnapper'. In following the archwiki page https://wiki.archlinux.org/index.php/Systemd/Timers I've tried to assemble a daily backup timer. I've created a file named tarsnapper.service:

[Unit]
Description=Tarsnap backup via Tarsnapper

[Service]
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
User=alex404
StandardOutput=journal
ExecStart=/home/alex404/.cabal/bin/tarsnapper

and a file tarsnapper.timer

[Unit]
Description=Daily Tarsnapper backup

[Timer]
# see systemd.time(7) manual page for other scheduling options
OnCalendar=daily
# run immediately if we missed a backup for some reason
Persistent=true

[Install]
WantedBy=timers.target

which I've enabled.

Now, the timer runs the service, but the odd thing is that the service does run properly. In particular, I can see that tarsnapper is excuting the commands 'tarsnap --list-archives', but it does not seem to parse the text/respond to it in the usual way. What's especially strange is that if I execute 'sudo systemctl start tarsnapper.service', it will run tarsnapper and have it execute correctly as if I'd simply entered 'tarsnapper' at the command line.

Is there some subtle way in which stdin/out and such are processed differently when I run things in the command line vs have them activated by timers?

Thanks!

Last edited by alex404 (2014-11-01 11:13:56)

Offline

#2 2014-10-15 21:30:16

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,304

Re: [SOLVED] script.service activated by script.timer behaves unusually

Can you post the script tarsnapper and what it writes in the journal when you start the service manually and when the timer starts it automatically.

Last edited by berbae (2014-10-15 21:30:33)

Offline

#3 2014-10-17 08:39:47

alex404
Member
Registered: 2009-12-03
Posts: 51

Re: [SOLVED] script.service activated by script.timer behaves unusually

Hey, sorry for the slow response. I looked into my journalctl and noticed that rather obvious fact that tarsnapper is failing because it tries to run before my computer has had time to establish an internet connection. I'm going to see if I can fix this in a reasonable way, and then report back my results.

Offline

#4 2014-11-01 11:13:00

alex404
Member
Registered: 2009-12-03
Posts: 51

Re: [SOLVED] script.service activated by script.timer behaves unusually

Okay, just to close this off for anyone having a similar newbie problem, add the lines

Restart=on-failure
RestartSec=600

to the backup.service file to get it to restart every ten minutes until it exits properly. This should be enough for a robust, persistent, daily backup.

Offline

#5 2014-11-01 13:00:47

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] script.service activated by script.timer behaves unusually

Or you could just set the correct service type. Your service is Type=oneshot, not the default of Type=simple...

Last edited by falconindy (2014-11-01 13:01:20)

Offline

#6 2014-11-02 10:45:40

serdotlinecho
Member
Registered: 2013-01-26
Posts: 100

Re: [SOLVED] script.service activated by script.timer behaves unusually

alex404 wrote:

Hey, sorry for the slow response. I looked into my journalctl and noticed that rather obvious fact that tarsnapper is failing because it tries to run before my computer has had time to establish an internet connection. I'm going to see if I can fix this in a reasonable way, and then report back my results.

Try add this in tarsnapper.service:

[Unit]
Description=Tarsnap backup via Tarsnapper
After=network.target

Last edited by serdotlinecho (2014-11-02 10:53:17)

Offline

Board footer

Powered by FluxBB