I am trying to restart my tomcat 8 server after deployment.
Setup:
gitlab-runner runs with its own user (called gitlab-runner)
tomcat uses its own user called tomcat
sudoers has an entry so that gitlab-runner can run a script:
gitlab-runner ALL=(tomcat) NOPASSWD: /home/tomcat/deploy.sh
The deploy script simply copies a file into the webapps directory, shuts down tomact and restarts it:
cd /home/tomcat/bin
sh catalina.sh stop -force
...
sh catalina.sh start
When I run the script manually as the gitlab-runner user everything works fine:
sudo -u tomcat /home/tomcat/deploy.sh
However, when the job is started from the gitlab-ci-multi-runner (with a push to the gitlab repository) the following things are happening. The gitlab-runner basically writes a script.sh which then executes the same command from above.
- Usually when I start tomcat I see the following output: For shutdown:
Using CATALINA_BASE: /home/tomcat/
Using CATALINA_HOME: /home/tomcat/
Using CATALINA_TMPDIR: /home/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /home/tomcat/bin/bootstrap.jar:/home/tomcat/bin/tomcat-juli.jar
Using CATALINA_PID: /home/tomcat/bin/catalina.pid
For startup:
Using CATALINA_BASE: /home/tomcat/
Using CATALINA_HOME: /home/tomcat/
Using CATALINA_TMPDIR: /home/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /home/tomcat/bin/bootstrap.jar:/home/tomcat/bin/tomcat-juli.jar
Using CATALINA_PID: /home/tomcat/bin/catalina.pid
Existing PID file found during start.
Removing/clearing stale PID file.
Tomcat started.
When I start it with the gitlab-runner there is no output for shutdown but the server shuts down. This is actually working.
For the startup only Tomcat started.
shows.
A pid file is created with a pid inside but the process does not exist.
Logfiles are created but they are empty.
If I start the server in debug mode: sh catalina.sh jpda start
the file log/catalina.out just conatains one line: tomcat Listening for transport dt_socket at address: 8080
My thought was that the environment is different so I checked with the env
cmd. Everything is equal except that TERM=unknown
when it's started by the gitlab-runner.
Do you have any clues what might happens in the background or just things I could test?
gitlab-runner is open source and the script that starts the build script is this: https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/executors/shell/executor_shell.go#L36