You are not logged in.

#1 2014-08-10 17:29:14

maggie
Member
Registered: 2011-02-12
Posts: 255

Need to delay the start of a script with systemd

I want to run /usr/local/bin/myscript from systemd as a oneshot but I want to have the service file I create wait 10 sec before it runs that. I can add a sleep 10s to my script itself but wanted to know if there is a proper way to do it within systemd. I did not find the answer in the man pages.

Offline

#2 2014-08-10 18:13:10

sistematico
Member
From: Campo Grande / MS / Brasil
Registered: 2008-07-26
Posts: 97
Website

Re: Need to delay the start of a script with systemd


Lucas Saliés Brum
blog | medium | vk | twitter | github | .share
Forgive the spelling and grammar, English is not my native language.

Offline

#3 2014-08-10 19:14:56

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

Re: Need to delay the start of a script with systemd

maggie wrote:

I want to run /usr/local/bin/myscript from systemd as a oneshot but I want to have the service file I create wait 10 sec before it runs that. I can add a sleep 10s to my script itself but wanted to know if there is a proper way to do it within systemd. I did not find the answer in the man pages.

What does the script do?  Or I guess, more importantly, what is the 10 second delay waiting for?

If you just want to have it wait a bit before it runs, you can use a systemd.timer unit to achieve this.  But if you are waiting for a particular device to show up and be ready, I think you would want to use BindsTo=sys-devices-whatever-thing.device (or possibly After=sys-device-whatever-thing.device).

Offline

#4 2014-08-11 10:04:18

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,496

Re: Need to delay the start of a script with systemd

maggie wrote:

I did not find the answer in the man pages.

Hi, have a look at 'man systemd.service'  and specifically  'man systemd.service|grep -A 1000 TimeoutStartSec='
Should do the trick..

Offline

#5 2014-08-11 12:17:53

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

Re: Need to delay the start of a script with systemd

qinohe wrote:
maggie wrote:

I did not find the answer in the man pages.

Hi, have a look at 'man systemd.service'  and specifically  'man systemd.service|grep -A 1000 TimeoutStartSec='
Should do the trick..

No, no it does not. This is about how long systemd will wait for a service to finish startup, not about delaying it.

OP is asking an XY question.

Last edited by falconindy (2014-08-11 12:18:35)

Offline

#6 2014-08-11 12:26:33

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: Need to delay the start of a script with systemd

@maggie You can use a timer for that. OnActiveSec is the directive. The timer file should be executed by systemctl or services you want it to, and after the time specified it will start the service. For more information check 'man systemd.timer'.

Offline

#7 2014-08-11 12:56:16

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Need to delay the start of a script with systemd

falconindy wrote:

OP is asking an XY question.

Indeed.  Maggie, how about telling is what "myscript" is and why you think it needs to wait 10 seconds?  Is 10 seconds just a guess or an estimate of how long it takes for the conditions required for your script to be ready?  If so, you'll never know when that guess will not be quite right.  I suspect you should be using service file Requires and/or After directives.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2014-08-11 16:04:52

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,496

Re: Need to delay the start of a script with systemd

falconindy wrote:
qinohe wrote:
maggie wrote:

I did not find the answer in the man pages.

Hi, have a look at 'man systemd.service'  and specifically  'man systemd.service|grep -A 1000 TimeoutStartSec='
Should do the trick..

No, no it does not. This is about how long systemd will wait for a service to finish startup, not about delaying it.

OP is asking an XY question.

I have completely misinterpreted that part of the man page, thanks for pointing me at it.

Offline

Board footer

Powered by FluxBB