Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upstart stop if running

I have a Jenkins job to stop a node application, deploy code, and start the application.

The start/stop is done with an Upstart script.

I use initctl stop node-App

If the job is running, this works great. But if the app has died or is in a stopped state, the output is initctl: Unknown instance:

This causes the Jenkins job to fail and not proceed to the next steps.

Is there a way to check if the job is started before issuing the start command? Or is there a way for Jenkins to not consider that an error and fail the job?

like image 588
jsmickey Avatar asked Jan 30 '14 21:01

jsmickey


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.

What is Initctl?

Description. initctl allows a system administrator to communicate and interact with the Upstart init(8) daemon. When run as initctl, the first non-option argument is the COMMAND. Global options may be specified before or after the command. You may also create symbolic or hard links to initctl named after commands.


1 Answers

A colleague came up with a great solution

if ( initctl status node-App | grep start ); then
  initctl stop node-App
fi

Very simple and works properly when run from Jenkins

like image 58
jsmickey Avatar answered Sep 30 '22 00:09

jsmickey