Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins seems to be the target for nohup in a script started via ssh, how can I prevent that?

Tags:

unix

ssh

jenkins

I am trying to create a Jenkins job that restarts a program that runs all the time on one of our servers.

I specify the following as the command to run:

cd /usr/local/tool && ./tool stop && ./tool start

The script 'tool' contains a line like:

nohup java NameOfClass &

The output of that ends up in my build console instead of in nohup.out, so the job never terminates unless I terminate it manually, which terminates the program.

How can I cause nohup to behave the same way it does from a terminal?

like image 634
Ricky Clarkson Avatar asked Jan 18 '23 07:01

Ricky Clarkson


2 Answers

If I understood the question correctly, Jenkins is killing all processes at the end of the build and you would like some process to be left running after the build has finished.

You should read https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller

Essentially, Jenkins searches for processes with some secret value in BUILD_ID environment variable. Just override it for the processes you want to be left alone.

like image 141
sti Avatar answered Jan 31 '23 05:01

sti


In the new Pipeline jobs, setting BUILD_ID no longer prevents Jenkins from killing your processes once the job finishes. Instead, you need to set JENKINS_NODE_COOKIE:

sh 'JENKINS_NODE_COOKIE=dontKillMe nohup java NameOfClass &'

See the wiki on ProcessTreeKiller and this comment in the Jenkins Jira for more information.

like image 43
jpyams Avatar answered Jan 31 '23 06:01

jpyams