0

I am trying to write an upstart script that checks if my process is running by pinging it's HTTP interface. So far, I just can't get the post-start clause to work. Here's a simplified version that I've tried:

description "my application"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 360 180
setuid myuser
setgid mygroup

chdir /my/directory
exec /bin/sleep 60

post-start script
  sleep 5
  stop
  exit 1
end script

From terminal:

/etc/init$ sudo start myapp   # returns after 5 seconds
myapp start/running, process 27477
jrantil@myserver:/etc/init$ ps -ef|grep sleep
107      27477     1  0 16:56 ?        00:00:00 /bin/sleep 60
jrantil  27482 26900  0 16:56 pts/1    00:00:00 grep --color=auto sleep

Could anyone tell me why my application is not shutting down after 5 seconds? As far as I've understood, if I don't call stop it will simply respawn.

0

You probably want to make this a task script, not a service script. That means that the Upstart init daemon will not expect it to remain running, and will not attempt to restart it or track the PID. Replace the stop, exec, and post-start stanzas with a task directive, leaving something like this:

description "my application"

start on runlevel [2345]
task

setuid myuser
setgid mygroup

chdir /my/directory
exec /bin/sleep 5

Obviously, replace the exec line with something meaningful for you. Perhaps you want a script to run a few commands in a row. If instead your process never stops by itself, and you want Upstart to kill it after 5 seconds, try this:

description "my application"

start on runlevel [2345]
stop on kill-me-please

setuid myuser
setgid mygroup

chdir /my/directory
exec /bin/sleep 60

post-start script
    /bin/sleep 5
    initctl emit kill-me-please
end script
  • I guess I should have been more specific; my main process is asctually a long running java process, to I don't think task is the right way to go. Also, I tried your second example and it seems to block forever. – Ztyx Mar 20 '14 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.