1

I have the following three services: apache2, serviceFirst and serviceSecond.

I want to run serviceFirst when apache2 is up and running

I want to run serviceSecond when serviceFirst is up and running

file /etc/init/serviceFirst.conf:

# Info
description "UDP server"
author "Reggie Williams"

# Events
start on apache2
stop on shutdown

# Automatically respawn
respawn
respawn limit 20 5

script 
     exec >/var/log/test.debug 2>&1 #so I can track when the service runs
     echo Gotcha...
    [ $(exec /usr/bin/php -f /var/www/server/udp/bin/serverrunner.php) = 'critical_error' ] && (stop; exit 1;)
end script

file /etc/init/serviceSecond.conf:

# Info
description "UDP client"
author "Reggie Williams"

# Events
start on (started serviceFirst)
stop on shutdown

# Automatically respawn
respawn
respawn limit 20 5

script 
     exec >/var/log/test2.debug 2>&1 #so I can track when the service runs
     echo Gotcha2...
    [ $(exec /usr/bin/php -f /var/www/server/udp/bin/clientrunner.php) = 'critical_error' ] && (stop; exit 1;)
end script

So in these two services I run my scripts. Besides that I create one file per service and save them in /var/log.

However when I check timestamps of creation of these two files I can see that test.debug was created later than test2.debug.

So my question is: how is this possible and how to make sure that serviceSecond is really started after serviceFirst and apache?

  • have you found the solution? thanks! – Cmag Jan 18 '16 at 0:38
  • yes, I had to edit apache upstart file and manually add "initctl emit apache2-started" command, because apache does not emit this event on ubuntu 14.04 with upstart. This is no longer an issue with systemd – user1762087 Apr 11 at 10:36
0

Maybe you can run service from /etc/rc.local with &&

edit /etc/rc.local

sudo nano /etc/rc.local

and add command

start service first && start service second

&& lets you do something based on whether the previous command completed successfully

To be More precisely, && will evaluate the second expression iff the first expression returns 0.

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.