Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I call a shell script to start a backend Java process?

Tags:

jenkins

After completing a Jenkins task, I execute a Linux shell script by using Jenkins' post-condition configuration section.

This Linux shell script wants to launch a standby service on the backend and can NOT cause Jenkins to pause.

I tried to use "nohup+&", etc., but it does not work.

Is there a good way to do it?

like image 807
aaronchen2k Avatar asked Sep 04 '26 12:09

aaronchen2k


1 Answers

Jenkins is probably waiting for some pipes to close. Your background process has inherited some file descriptors and is keeping them open for as long as it runs.

If you are lucky, the only file descriptors are 0, 1 and 2 (the standard ones.) You might want to check the file descriptors of the background process using lsof -p PID where PID is the process id of the background process.

You should make sure all of those file descriptors (both inputs and outputs) are redirected for the background process, so start it with something like:

nohup daemon </dev/null >/dev/null 2>&1 &

Feel free to direct the output to a file other than /dev/null but make sure you keep the order of the redirections. The order is important.

If you plan to start background processes from a Jenkins job, be advised that Jenkins will kill background processes when build ends. See https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller on how to prevent that.

like image 128
sti Avatar answered Sep 07 '26 22:09

sti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!