From b4da93c2e763d1a4bea7bfed99326c4f6d1ba21c Mon Sep 17 00:00:00 2001 From: morph027 Date: Tue, 28 May 2024 08:50:17 +0200 Subject: [PATCH] change tests to init instead of systemd Signed-off-by: morph027 --- .gitlab-ci.yml | 36 ++--------------- .gitlab-ci/init | 84 +++++++++++++++++++++++++++++++++++++++ .gitlab-ci/test-update.sh | 2 +- .gitlab-ci/test.sh | 12 ++++-- 4 files changed, 97 insertions(+), 37 deletions(-) create mode 100755 .gitlab-ci/init diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6dc12fd..210734b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -92,45 +92,17 @@ gitea-arm64-trigger: .test-install: &test-install stage: test - image: docker:stable - services: - - docker:stable-dind + image: ubuntu:noble variables: DOCKER_TLS_CERTDIR: "" script: - - docker run - -d - --name systemd-ubuntu - --tmpfs /tmp - --tmpfs /run - --tmpfs /run/lock - -v /sys/fs/cgroup:/sys/fs/cgroup:ro - -v $CI_PROJECT_DIR:/src - -e CI_PROJECT_DIR=/src - -e CI_COMMIT_TAG=$CI_COMMIT_TAG - jrei/systemd-ubuntu:20.04 - - docker exec -t systemd-ubuntu /bin/bash /src/.gitlab-ci/test-install.sh + - ./.gitlab-ci/test-install.sh .test-update: &test-update stage: test - image: docker:stable - services: - - docker:stable-dind - variables: - DOCKER_TLS_CERTDIR: "" + image: ubuntu:noble script: - - docker run - -d - --name systemd-ubuntu - --tmpfs /tmp - --tmpfs /run - --tmpfs /run/lock - -v /sys/fs/cgroup:/sys/fs/cgroup:ro - -v $CI_PROJECT_DIR:/src - -e CI_PROJECT_DIR=/src - -e CI_COMMIT_TAG=$CI_COMMIT_TAG - jrei/systemd-ubuntu:20.04 - - docker exec -t systemd-ubuntu /bin/bash /src/.gitlab-ci/test-update.sh + - ./.gitlab-ci/test-update.sh test-install-trigger: <<: *test-install diff --git a/.gitlab-ci/init b/.gitlab-ci/init new file mode 100755 index 0000000..f78371d --- /dev/null +++ b/.gitlab-ci/init @@ -0,0 +1,84 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: gitea +# Required-Start: $syslog $network +# Required-Stop: $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: A self-hosted Git service written in Go. +# Description: A self-hosted Git service written in Go. +### END INIT INFO + +# Do NOT "set -e" + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin +DESC="Gitea - Git with a cup of tea" +NAME=gitea +SERVICEVERBOSE=yes +PIDFILE=/run/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME +WORKINGDIR=/var/lib/$NAME +DAEMON=/usr/bin/$NAME +DAEMON_ARGS="web -c /etc/$NAME/app.ini" +USER=gitea +STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/1/KILL/5}" + +# Read configuration variable file if it is present +[ -r /etc/default/$NAME ] && . /etc/default/$NAME + +# Exit if the package is not installed +[ -x "$DAEMON" ] || exit 0 + +do_start() +{ + GITEA_ENVS="USER=$USER GITEA_WORK_DIR=$WORKINGDIR HOME=/var/lib/$USER" + GITEA_EXEC="$DAEMON -- $DAEMON_ARGS" + sh -c "start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\ + --background --chdir $WORKINGDIR --chuid $USER \\ + --exec /bin/bash -- -c '/usr/bin/env $GITEA_ENVS $GITEA_EXEC'" +} + +do_stop() +{ + start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PIDFILE --name $NAME --oknodo + rm -f $PIDFILE +} + +do_status() +{ + if [ -f $PIDFILE ]; then + if kill -0 $(cat "$PIDFILE") >/dev/null 2>&1; then + echo "$NAME is running, PID is $(cat $PIDFILE)" + else + echo "$NAME process is dead, but pidfile exists" + fi + else + echo "$NAME is not running" + fi +} + +case "$1" in + start) + echo "Starting $DESC" "$NAME" + do_start + ;; + stop) + echo "Stopping $DESC" "$NAME" + do_stop + ;; + status) + do_status + ;; + restart) + echo "Restarting $DESC" "$NAME" + do_stop + do_start + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2 + exit 2 + ;; +esac + +exit 0 diff --git a/.gitlab-ci/test-update.sh b/.gitlab-ci/test-update.sh index 060f32f..3f166f3 100644 --- a/.gitlab-ci/test-update.sh +++ b/.gitlab-ci/test-update.sh @@ -6,7 +6,7 @@ curl -sL -o /etc/apt/trusted.gpg.d/morph027-gitea.asc https://packaging.gitlab.i echo "deb [arch=amd64] https://packaging.gitlab.io/gitea gitea main" > /etc/apt/sources.list.d/morph027-gitea.list apt-get update apt-get -y install gitea -cp "/${CI_PROJECT_DIR}/.gitlab-ci/app.ini" /etc/gitea/app.ini +install -o gitea -g gitea -m 644 "/${CI_PROJECT_DIR}/.gitlab-ci/app.ini" /etc/gitea/app.ini start_gitea curl -s localhost:3000/api/v1/version | jq -e '.version' apt-get -y --allow-downgrades install "${CI_PROJECT_DIR}/gitea_${VERSION}+${PATCHLEVEL}_amd64.deb" diff --git a/.gitlab-ci/test.sh b/.gitlab-ci/test.sh index 7f004e4..b5a3a35 100644 --- a/.gitlab-ci/test.sh +++ b/.gitlab-ci/test.sh @@ -6,16 +6,20 @@ VERSION=$(echo "${CI_COMMIT_TAG#*v}" | cut -d'+' -f1) PATCHLEVEL=$(echo "${CI_COMMIT_TAG}" | cut -d'+' -f2) export VERSION PATCHLEVEL +if [ ! -f /etc/init.d/gitea ]; then + install -m 755 "${CI_PROJECT_DIR}"/.gitlab-ci/init /etc/init.d/gitea +fi + start_gitea() { - systemctl start gitea + /etc/init.d/gitea start sleep 10 - if ! systemctl is-active gitea; then - journalctl -lu gitea --no-pager + if ! /etc/init.d/gitea status | grep 'gitea is running'; then + cat /var/lib/gitea/log/gitea.log fi } restart_gitea() { - systemctl stop gitea + /etc/init.d/gitea stop start_gitea }