Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UpStart initctl start|restart ubuntu

Tags:

upstart

When using upstart on ubuntu how do I issue a command for starting a job if not running and restarting if already running. When deploying an app to a new node the job is not defined.

initctl restart JOB complains if not already running
initctl start JOB complains if already running.

I can script it to do

initctl start JOB
initctl restart JOB

But it doesn't seem to be the nicest thing to do.

like image 200
Niclas Avatar asked Feb 28 '12 09:02

Niclas


People also ask

What is Ubuntu Upstart mode?

Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running.

Where is init d in Ubuntu?

/etc/init is where the upstart init configs live. While they are not scripts themselves, they essentially execute whatever is required to replace sysvinit scripts. /etc/init. d is where all the traditional sysvinit scripts and the backward compatible scripts for upstart live.

What does initctl do?

DESCRIPTION. initctl allows a system administrator to communicate and interact with the Upstart init(8) daemon. If D-Bus has been configured to allow non-privileged users to invoke all Upstart D-Bus methods, this command is also able to manage user jobs.

Where are Upstart files?

Processes are known to Upstart as jobs and are defined by files in the /etc/init directory.


1 Answers

I was in front of the same problem. Short of a straight "lazy-stop-then-start" command built-in initctl, we have to script.

Invoke start and restart if it fails:

initctl start JOB || initctl restart JOB

This script is probably not the answer both of us were looking for but it is short enough to mention it.

As long as the service works nicely, it will do the trick.

When the services fails, this script fails twice; For example, if the service was stopped and actually fails to start, it will also fail to restart.

Definitely looking for an improvement to this.

I hope this helps.

like image 62
hmalphettes Avatar answered Oct 06 '22 22:10

hmalphettes