Skip to content

Commit

Permalink
feat: add support for sysvinit
Browse files Browse the repository at this point in the history
  • Loading branch information
VMelnalksnis committed Oct 13, 2024
1 parent d0d072b commit 8acf9fe
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 13 deletions.
30 changes: 22 additions & 8 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ jobs:
needs: build-deb
strategy:
matrix:
distro:
- debian10
- debian11
- debian12
- ubuntu2004
- ubuntu2204
- ubuntu2404
image:
- geerlingguy/docker-debian10-ansible:latest
- geerlingguy/docker-debian11-ansible:latest
- geerlingguy/docker-debian12-ansible:latest
- geerlingguy/docker-ubuntu2004-ansible:latest
- geerlingguy/docker-ubuntu2204-ansible:latest
- geerlingguy/docker-ubuntu2404-ansible:latest
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
Expand All @@ -129,7 +129,21 @@ jobs:
with:
molecule_working_dir: './deployment/ansible/gnomeshade'
env:
MOLECULE_DISTRO: ${{ matrix.distro }}
MOLECULE_IMAGE: ${{ matrix.image }}

test-deb:
name: Test debian package
runs-on: ubuntu-20.04
timeout-minutes: 10
needs: build-deb
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
id: download
with:
name: Gnomeshade.WebApi_linux-x64.deb

- run: ./deployment/test-deb.sh ${{ steps.download.outputs.download-path }}/gnomeshade.deb ${{ secrets.DEMO_ADMIN_PASSWORD }}

docker:
name: Test docker container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ driver:
name: docker
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
image: "${MOLECULE_IMAGE}"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
Expand Down
5 changes: 5 additions & 0 deletions deployment/debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ strip gnomeshade/opt/gnomeshade/libe_sqlite3.so
mkdir -p gnomeshade/DEBIAN
cp deployment/debian/postinst gnomeshade/DEBIAN/postinst
cp deployment/debian/prerm gnomeshade/DEBIAN/prerm
cp deployment/debian/postrm gnomeshade/DEBIAN/postrm

export FULL_VERSION=$full_version
export MAINTAINER=$maintainer
Expand All @@ -46,6 +47,10 @@ mv changelog.gz $changelog_path
mkdir -p gnomeshade/lib/systemd/system
cp deployment/debian/gnomeshade.service gnomeshade/lib/systemd/system/gnomeshade.service

mkdir -p gnomeshade/etc/init.d
cp deployment/debian/gnomeshade gnomeshade/etc/init.d/gnomeshade
echo "/etc/init.d/gnomeshade" >>gnomeshade/DEBIAN/conffiles

dpkg-deb --root-owner-group --build gnomeshade

# unstripped-binary-or-object suppressed because gnomeshade/opt/gnomeshade/Gnomeshade.WebApi
Expand Down
124 changes: 124 additions & 0 deletions deployment/debian/gnomeshade
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash

### BEGIN INIT INFO
# Provides: gnomeshade
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Gnomeshade server
### END INIT INFO

# Source LSB helpers
. /lib/lsb/init-functions

# Process name (for display only)
NAME=gnomeshade

# Where is the actual executable for the daemon
DAEMON=/opt/gnomeshade/Gnomeshade.WebApi
WORKING_DIRECTORY=/etc/opt/gnomeshade
ASPNETCORE_WEBROOT=/opt/gnomeshade/wwwroot
ENVIRONMENT=Production
DOTNET_gcServer=0
Database__Provider="Sqlite"
ConnectionStrings__Gnomeshade="Data Source=gnomeshade.db"

# The user:group under which the daemon must run
RUN_AS_USER=gnomeshade

# pid file for the daemon
PIDFILE=/var/run/gnomeshade.pid

# If the daemon is not there, then exit.
if ! [ -x ${DAEMON} ]
then
log_failure_msg "Cannot find an executable at ${DAEMON}"
exit 1
fi

case $1 in
start)
# Check if pidfile exists
if [ -e ${PIDFILE} ]
then
# Check the actual status of process
status_of_proc -p ${PIDFILE} ${DAEMON} ${NAME} && status="0" || status="$?"
# If the status is successfully, no need to start again.
[ "${status}" = "0" ] && exit 0
fi
# Start the daemon.
log_daemon_msg "Starting ${NAME}"
# Start the daemon with the help of start-stop-daemon
if start-stop-daemon --start --quiet --oknodo --pidfile ${PIDFILE} --make-pidfile --background \
--chuid ${RUN_AS_USER} --chdir ${WORKING_DIRECTORY} --no-close --startas ${DAEMON} >> /var/log/gnomeshade
then
log_end_msg 0
else
log_end_msg 1
fi
;;
stop)
if [ -e ${PIDFILE} ]
then
status_of_proc -p ${PIDFILE} ${DAEMON} ${NAME} && status="0" || status="$?"
if [ "$status" = "0" ]; then
log_daemon_msg "Stopping ${NAME}"
if start-stop-daemon -K --signal TERM --quiet --oknodo --pidfile ${PIDFILE}
then
log_end_msg 0
rm -rf ${PIDFILE}
else
log_end_msg 1
fi
fi
else
log_daemon_msg "${NAME} is not running"
log_end_msg 0
fi
;;
restart)
$0 stop && sleep 3 && $0 start
;;
status)
# Check the status of the process.
if [ -e ${PIDFILE} ]
then
status_of_proc -p ${PIDFILE} ${DAEMON} ${NAME} && exit 0 || exit $?
else
log_daemon_msg "${NAME} is not running (no pidfile)"
log_end_msg 0
fi
;;
reload)
if [ -e ${PIDFILE} ]; then
log_daemon_msg "Reloading ${NAME}"
if start-stop-daemon -K --quiet --signal HUP --pidfile ${PIDFILE}
then
log_end_msg 0
else
log_end_msg 1
fi
else
log_failure_msg "Cannot find pidfile at ${PIDFILE}"
fi
;;
force-reload)
if [ -e ${PIDFILE} ]; then
log_daemon_msg "Reloading ${NAME}"
if start-stop-daemon -K --quiet --signal HUP --pidfile ${PIDFILE}
then
log_end_msg 0
else
log_end_msg 1
fi
else
log_failure_msg "Cannot find pidfile at ${PIDFILE}"
fi
;;
*)
# Invalid argument, print the usage message.
echo "Usage: $0 {start|stop|restart|reload|force-reload|status}"
exit 2
;;
esac
13 changes: 10 additions & 3 deletions deployment/debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ set -e

GNOMESHADE_USER=gnomeshade

if [[ -z "$(getent group ${GNOMESHADE_USER})" ]]; then
if [[ -z "$(getent group ${GNOMESHADE_USER})" ]]
then
addgroup --system ${GNOMESHADE_USER}
fi

if [[ -z "$(getent passwd ${GNOMESHADE_USER})" ]]; then
if [[ -z "$(getent passwd ${GNOMESHADE_USER})" ]]
then
adduser \
--system --ingroup ${GNOMESHADE_USER} ${GNOMESHADE_USER} \
--no-create-home --home /nonexistent \
Expand All @@ -17,4 +19,9 @@ fi
chown gnomeshade /etc/opt/gnomeshade --recursive
chown gnomeshade /opt/gnomeshade --recursive

deb-systemd-invoke enable gnomeshade.service
if [[ $(systemctl) =~ -\.mount ]]
then
deb-systemd-invoke enable gnomeshade.service
else
update-rc.d gnomeshade defaults
fi
9 changes: 9 additions & 0 deletions deployment/debian/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

if [[ $(systemctl) =~ -\.mount ]]
then
exit
else
update-rc.d gnomeshade remove
fi
7 changes: 6 additions & 1 deletion deployment/debian/prerm
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash
set -e

deb-systemd-invoke stop gnomeshade.service
if [[ $(systemctl) =~ -\.mount ]]
then
deb-systemd-invoke stop gnomeshade.service
else
exit
fi
8 changes: 8 additions & 0 deletions deployment/docker/devuan/daedalus/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM devuan/devuan:daedalus

COPY gnomeshade.deb /gnomeshade.deb

RUN apt-get update && apt-get install -y libicu72 libssl3 libgssapi-krb5-2
RUN dpkg -i /gnomeshade.deb

EXPOSE 5000
File renamed without changes.
36 changes: 36 additions & 0 deletions deployment/test-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -e

name="test"

function printLogs() {
docker logs $name
docker exec $name service --status-all
docker exec $name ls -lah /opt/gnomeshade
docker exec $name ls -lah /etc/opt/gnomeshade
docker exec $name ls -lah /var/log
docker exec $name cat /var/log/gnomeshade
}

trap printLogs EXIT

cd ./deployment/docker/devuan/daedalus
cp "$1" ./gnomeshade.deb

docker build --tag devuan:test ./
docker pull devuan/devuan:daedalus
docker run --detach --name $name --publish 5000:5000 \
--env "Admin__Password=$2" \
devuan:test /bin/bash -c \
"service gnomeshade start && { while true; do sleep 2; done }"

wget --tries=10 --retry-connrefused --waitretry=10 --timeout=15 "http://localhost:5000/api/v1.0/health"

if [[ $(cat health) != "Healthy" ]]; then
exit 1
fi

curl --header "Content-Type: application/json" \
--request POST \
--data '{"username":"john.doe", "password": "Password123!", "email": "[email protected]", "fullName": "John Doe" }' \
http://localhost:8000/Authorization/Register

0 comments on commit 8acf9fe

Please sign in to comment.