You are not logged in.

#1 2015-09-10 08:39:24

bergqvistjl
Member
Registered: 2011-01-05
Posts: 55

How can I Auto-run mythfilldatabase via Systemd timers?

I would like to migrate a cron job that I had set up to run mythfilldatabase (followed by another script) daily at 6AM, into a SystemD timer job. I would like the job to be run under a particular user (called mythtv), even though that user may be logged out & no other user be logged in. These are the files I have created:

/etc/systemd/system/mythfilldatabase.service:

[Unit]
Description=Runs mythfilldatabase, then hd_update.sh under the mythtv user

[Service]
Type=oneshot
User=mythtv
ExecStart=/usr/bin/mythfilldatabase --only-update-guide --refresh 0 --refresh 1 --refresh 2
ExecPost=/home/mythtv/hd_update.sh #Script to be run after mythfilldatabase completes - whether sucessful or not.


/etc/systemd/system/mythfilldatabase.timer

[Unit]
Description=Runs mythfilldatabase at 6AM every day

[Timer]
OnCalendar=*-*-* 06:00:00



However while mythfilldatabase runs, it errors as it is either unable to access the grabber script (stored in /usr/bin/site_perl) or unable to access my XMLTV config file stored in /mythtv/.mythtv/Satellite.xmltv

I don't get these errors when I run the command manually when logged in. /usr/bin/site_perl is stored within my PATH variable in /etc/profile so it should be able to access the grabber OK.

Can anyone help?

It turns out that despite the path in /etc/profile being different, if I echo $PATH out my hd_update script, it only gives me:  "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" which would explain why Mythfilldatabase is running. How can I alter that version of PATH permanently?

Last edited by bergqvistjl (2015-09-10 08:52:29)

Offline

#2 2015-09-10 09:35:49

Rotech
Member
Registered: 2009-06-02
Posts: 11

Re: How can I Auto-run mythfilldatabase via Systemd timers?

You are not getting a full login shell (/etc/profile ~.bashrc are not sourced)

Easiest way is to add an Environment line something like

Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/bin/site_perl/

Offline

#3 2015-09-10 09:39:35

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,911

Re: How can I Auto-run mythfilldatabase via Systemd timers?

or use

EnvironmentFile=/etc/profile

man systemd.exec(5) has details of those options.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

Board footer

Powered by FluxBB