Commit abefd5f6 authored by Kamil Trzciński's avatar Kamil Trzciński 🔴

Fix service installation and upgrade

parent 563237e7
......@@ -4,36 +4,43 @@ set -e
# detect user: first try to use gitlab_ci_multi_runner
for USER in gitlab_ci_multi_runner gitlab_runner; do
if id -u "$USER" &>/dev/null; then
echo "GitLab Runner: detected $USER"
continue
if id -u "$USER" >/dev/null 2>/dev/null; then
echo "GitLab Runner: detected user $USER"
break
fi
done
# create user if doesn't exist: it will create gitlab_runner if not found
if ! id -u "$USER" &>/dev/null; then
if ! id -u "$USER" >/dev/null 2>/dev/null; then
echo "GitLab Runner: creating $USER..."
useradd --comment 'GitLab Runner' --create-home $USER
fi
# add user to docker group to allow Docker access (insecure)
if id -nG "$USER" | grep docker; then
if id -nG "$USER" | grep -q docker; then
echo "WARNING: $USER belongs to group docker which is insecure, because allows to have root access to host"
fi
# get USER home directory
eval HOMEDIR=~$USER
# create empty config and re-register runner
mkdir -p /etc/gitlab-runner
chmod 0700 /etc/gitlab-runner
if [[ -e ~$USER/config.toml ]]; then
if [ -f $HOMEDIR/config.toml ] && [ ! -f /etc/gitlab-runner/config.toml ]; then
echo "GitLab Runner: importing configuration to /etc/gitlab-runner/config.toml"
cp ~$USER/config.toml /etc/gitlab-runner/config.toml
cp $HOMEDIR/config.toml /etc/gitlab-runner/config.toml
chmod 0600 /etc/gitlab-runner/config.toml
fi
# uninstall old service
gitlab-ci-multi-runner stop --service "gitlab-ci-multi-runner" >/dev/null 2>/dev/null || :
gitlab-ci-multi-runner uninstall --service "gitlab-ci-multi-runner" >/dev/null 2>/dev/null || :
# re-register runner
gitlab-ci-multi-runner stop &>/dev/null || :
gitlab-ci-multi-runner uninstall &>/dev/null || :
gitlab-ci-multi-runner install --user=$USER
gitlab-ci-multi-runner stop >/dev/null 2>/dev/null || :
gitlab-ci-multi-runner uninstall >/dev/null 2>/dev/null || :
gitlab-ci-multi-runner install --user=$USER --working-directory=$HOMEDIR
# start runner service
service gitlab-ci-multi-runner start || :
service gitlab-runner start || :
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment