Why is this a bad idea?
As its documentation says, GitLab Runner runs tests and sends the results to GitLab. "
And since the tests must start and stop in a timely manner, the runner is designed to destroy all created processes after the completion of each assembly.
So itβs not a mistake that your service is killed, this is a feature .;)
GitLab CI Documentation recommends using dpl for deployment .
dpl is a project that allows you to deploy your application to various PaaS providers, such as Google App Engine, Heroku, or Elastic Beanstalk.
Thus, it calls some requests to some REST APIs or pushes other data over the Internet, and its process finishes perfectly.
So doing what you want to do requires some hacking - overriding the default behavior for runners. And you should not do this as a long-term solution, because it may stop working with some runner / gitlab update.
... but if you insist, then here's how to do it :)
In your case, when you want to actually deploy and run the application on your runner host, we need to use two hacks:
- do not use the default
shell executable ssh , but ssh and make the ssh executor itself (inspired by michael 's solution to this question (please refrain his answer too if you are mine!), - edit the process that starts using the script solution ( Joe for this question (again - please raise it!)
So here are the instructions:
Make sure you can use SSH from your leader host using the SSH private key in /root/.ssh/id_rsa , without passphrase, without fingerprint confirmation. ssh localhost run by root should not work interactively.
Modify the gitlab-runner configuration file, /etc/gitlab-runner/config.toml so that it looks like this:
[[runners]] name = "your-runner-name" url = "https://<your_gitlab_instance_fqdn>/ci" token = "<your_project_CI_token>" tls-ca-file = "" executor = "ssh" [runners.ssh] user = "root" password = "" host = "localhost" port = "22" identity_file = "/root/.ssh/id_rsa"
(The runner will reboot after saving the configuration file)
Edit the script service so that the process it creates is NOT a child of the init script, and it will not open stdin, stdout and stderr:
#!/usr/bin/env bash export JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre/bin/java export MODE=service export APP_NAME=gitlab-runner-test export PID_FOLDER=/var/run/gitlab-runner-test /var/gitlab-runner-test/gitlab-runner-test.war $* <&- >&- 2>&- & disown
Testing by reassembling the last build or fixing your project repo.
PS I tested my solution with an init script that looks like this:
#!/usr/bin/env bash start() { # Completely disowned process, not a child # Credits: Joe at /questions/447838/how-can-i-launch-a-new-process-that-is-not-a-child-of-the-original-process/1961541#1961541 sleep 99999 <&- >&- 2>&- & disown exit 0 } stop() { echo "doing nothing" exit 0 } echo "running on $HOSTNAME..." case "$1" in start) start ;; stop) stop ;; *) echo $"Use this options $0 {start|stop}" exit 1 esac
.. on Ubuntu 14.04 with gitlab-multi-runner v. 1.02 and GitLab CE 8.5.0.