You are not logged in.

#1 2013-12-14 16:22:08

vendion
Member
From: Tennessee, USA
Registered: 2010-03-10
Posts: 204
Website

Problems setting up systemd/cron functionality

First of all I know that my problem can be solved by just running cron but that is not the point here.  I am trying this to see how well it works.  I followed the setup instructions on the systemd/cron functionality, and I created a fake hourly service to be able to watch it work.  The unit file for this is

[Unit]
Description=Run a test (echo) job every hour

[Service]
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
ExecStart=/bin/echo "I ran via a hourly job in SystemD" >> /tmp/test.log

The problem is it does not seem that the service file is being ran as a /tmp/test.log file never gets created.  Anyone ever play with this part of SystemD and get it working?

Offline

#2 2013-12-14 16:33:16

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Problems setting up systemd/cron functionality

What's the status of this service and related timers?

Offline

#3 2013-12-14 16:40:59

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Problems setting up systemd/cron functionality

ExecStart is not a shell.  You cannot put redirects there without first spawning a shell.

Offline

#4 2013-12-14 22:33:08

vendion
Member
From: Tennessee, USA
Registered: 2010-03-10
Posts: 204
Website

Re: Problems setting up systemd/cron functionality

karol wrote:

What's the status of this service and related timers?

Here is the status of the timers are:
timers.target: loaded active active
timer-daily.timer: loaded active waiting
timer-hourly.timer: loaded active waiting
timer-weekly.timer: loaded active waiting

That suggests to me that the timers are working, I don't see my test service under systemctl's output, but I see another service that I wrote to sync pacman's DB every hour has failed.  This is why I wrote the second service file in hopes to see if this was working.

Offline

#5 2013-12-14 23:54:20

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Problems setting up systemd/cron functionality

Again, ExecStart is not a shell.  So the redirected echo command is not going to work since redirections are a function of a shell.

Offline

#6 2013-12-15 00:59:05

vendion
Member
From: Tennessee, USA
Registered: 2010-03-10
Posts: 204
Website

Re: Problems setting up systemd/cron functionality

I understand that ExecStart does not support redirection as it is not a shell, which is why I wrote "in hopes".  The systemctl status and journalctl commands don't output anything useful to see why it was not working, I did that because I did not know any other way to debug this.

Offline

#7 2013-12-15 01:08:08

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Problems setting up systemd/cron functionality

Would 'ExecStart=/usr/bin/touch /tmp/test' work?

Offline

#8 2013-12-15 01:32:32

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Problems setting up systemd/cron functionality

Yeah that would work.  But you could also do something like:

ExecStart=/usr/bin/bash -c "/usr/bin/echo foo >> /path/to/file" 

Edit: That is what I was trying to point you to in saying you needed to spawn a shell.  But you could also just write a script as well that is launched by ExecStart.  I think you need to make sure that it has a valid shebang though.

Last edited by WonderWoofy (2013-12-15 01:34:00)

Offline

Board footer

Powered by FluxBB