I have a number of services in init.d that are simple one-line commands wrapped in a script that repeats every few seconds. The template for them looks like this:
e.g.
#!/bin/sh
autostart() {
while true
do
$@ ; sleep 20
done
}
case "$1" in
start)
echo " started"
autostart /path/to/checksomethingquickly
;;
stop)
me=`basename $0`
killall checksomethingquickly $me
;;
esac
## End of File
The crux of this "service" is to call checksomethingquickly every 20 seconds. (Hence it's too quick for cron.) We want it to start when told to, and kill any/all running instances when it's told to stop.
It looks to me like it could be a "Task Job" in upstart but I'm unclear on how to ensure that the Task is repeated indefinitely and separated by 20 seconds. Ensuring it's serialised would be a nice improvement, too.
Is this the kind of script that can be turned into a upstart script? If so, how?
0 Answers