Daemon hell in Jenkins

Recently I wrote a Linux like initd script to start/stop my web application.

The script works well when running it in shell of linux. The web application will run in background by daemon.

However I found both daemon and web application(java) exited immediately if I started the script in Jenkins as a shell step of build process.

I put below simple script in 'Execute shell' block,

1daemon --name=test-daemon -- sleep 200sleep 60

The process 'daemon' and 'sleep 200' should exit after 200 seconds the 'sleep' exits. The jenkins job will be finished in 60 secs.

jenkins   9954  9950  0 21:48 ?        00:00:00 sleep 60 
jenkins   9955     1  0 21:48 ?        00:00:00 daemon —name=test-daemon — sleep 200
jenkins   9956  9955  0 21:48 ?        00:00:00 sleep 200

Above is the process info queried via ps command. The father pid of daemon is 1, not the script generated by Jenkins.
But both the process 'daemon' and 'sleep 200' immediately exited when the script finished. Should be something wrong in Jenkins to cause daemon exited unexpected.

It's something really frustrating to use daemon to stop/start the web application in Jenkins.

Finally I used docker container to run my web application, which easily can be stopped/started via script in Jenkins.