Upstart stop if running
Asked Answered
S

2

8

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?

Smiley answered 30/1, 2014 at 21:25 Comment(0)
S
10

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

Smiley answered 6/2, 2014 at 21:21 Comment(3)
I simpler syntax would be status node-App | grep start && stop node-AppPhoenicia
@unnu: your one-liner would leave the return code as non-zero. I believe this might still cause Jenkins to fail. The above solution is better since it will set the return code to zero.Greek
@Greek The one-liner returns 0 if the job was shutdown and returns 1 if it was not running. Considering the question your answer is right ;)Phoenicia
H
0

I'm using similar construction

initctl stop node-App || echo "node-App was not running"
Hilliary answered 4/1, 2020 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.