You are not logged in.
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
Offline
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
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
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
@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
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
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