jenkins session issue

SSH remote execution script tomcat does not start


background:

Just to write a script to restart tomcat, let jenkins compile, package, and call it when publishing. After the script to restart tomcat is written locally, there is no problem in executing the script locally, but after the SSH password-free login is executed on the remote server. It was found that TOMCAT could be killed, but tomcat could not get up. This question has plagued me for a day. Finally solved it, and decided to write a blog post to share with you.


Let me share with you the weird phenomenon I encountered:

1. Is the script executed? sh -x Check the execution process of the script, it is indeed executed, and no error is reported. But when I go to the target server, there is no java process and no corresponding port. Damn, what's the reason?


2. Look at the log. The log was turned on when the script was executed remotely, and tail -f found that there was no log output at all.


3. Some people say it is an environment variable problem. Personally I don't think so. I can execute the script locally stating that it is not a problem with environment variables.


reason:

    My ansible command is like this ansible abcd -u root -m shell -a "sh -x /data/scripts/start_tomcat.sh"

I did a test myself. After I started tomcat in the script, I slept for 60 seconds. I saw that tomcat was started, there were logs, and I also saw the port. After 60 seconds, the port disappeared automatically. Write to the log.

The description can confirm one thing, "If this script is run remotely, the child process will be killed after the remote session ends."


Solution:

Add nohup before the startup command of the script, that is, as follows

nohup /data/server/apache-tomcat-8.0.47-8080/bin/startup.sh &


Another solution is

Just add this line to the shell script: BUILD_ID=DONTKILLME (when using jenkins) When configuring the automatic update deployment project in jenkins, if you use execute shell to start/close tomcat, you will find that you can close tomcat, but it cannot be started tomcat, although the build will show that the execution is successful, but looking at the process, tomcat is not started.


This is because Jenkins will kill all spawned processes by default after the Build is over.

The following configuration is required to avoid this situation: reset the environment variable build_id and add BUILD_ID=DONTKILLME in the execute shell input box to prevent jenkins from killing the started tomcat process


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324930773&siteId=291194637