Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ on:
env:
BUILD_TAG: librenms:test
CONTAINER_NAME: librenms
PUID: "1234"
PGID: "1235"

jobs:
test:
Expand Down Expand Up @@ -71,6 +73,17 @@ jobs:
name: ${{ env.CONTAINER_NAME }}
log_check: "ready to handle connections"
timeout: 120
-
name: Check services
run: |
for service in librenms dispatcher syslogng snmptrapd; do
docker compose exec -T "$service" sh -s < services.sh
done
docker compose exec -T librenms curl --fail --retry 5 --retry-connrefused http://127.0.0.1:8000/login
working-directory: test
env:
LIBRENMS_IMAGE: ${{ env.BUILD_TAG }}
LIBRENMS_CONTAINER: ${{ env.CONTAINER_NAME }}
-
name: Logs
if: always()
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARG SYSLOGNG_VERSION="4.11.0-r0"

FROM tianon/gosu:latest AS gosu

FROM crazymax/alpine-s6:${ALPINE_VERSION}-2.2.0.3
FROM alpine:${ALPINE_VERSION}
COPY --from=gosu /gosu /usr/local/bin/
RUN apk --update --no-cache add \
busybox-extras \
Expand Down Expand Up @@ -70,7 +70,7 @@ RUN apk --update --no-cache add \
python3 \
py3-pip \
rrdtool \
runit \
s6-overlay \
sed \
shadow \
ttf-dejavu \
Expand Down Expand Up @@ -105,6 +105,7 @@ ARG SYSLOGNG_VERSION
RUN apk --update --no-cache add syslog-ng=${SYSLOGNG_VERSION}

ENV S6_BEHAVIOUR_IF_STAGE2_FAILS="2" \
S6_STAGE2_HOOK="/etc/s6-overlay/scripts/runtime-bundles" \
LIBRENMS_PATH="/opt/librenms" \
LIBRENMS_DOCKER="1" \
TZ="UTC" \
Expand Down
13 changes: 0 additions & 13 deletions rootfs/etc/cont-init.d/01-fix-uidgid.sh

This file was deleted.

Empty file.
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/config/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
10 changes: 10 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/config/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
with-contenv
if { /etc/s6-overlay/scripts/fix-logs }
if { /etc/s6-overlay/scripts/fix-uidgid }
if { /etc/s6-overlay/scripts/fix-perms }
if { /etc/s6-overlay/scripts/config }
if { /etc/s6-overlay/scripts/config-main }
if { /etc/s6-overlay/scripts/config-dispatcher }
if { /etc/s6-overlay/scripts/config-syslogng }
if { /etc/s6-overlay/scripts/config-cron }
/etc/s6-overlay/scripts/config-snmptrapd
Empty file.
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/cron/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/command/with-contenv sh

exec busybox crond -f -L /dev/stdout -c /var/spool/cron/crontabs
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/cron/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
4 changes: 4 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/dispatcher/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/command/with-contenv sh

cd /opt/librenms || exit 1
exec s6-setuidgid "${PUID}:${PGID}" execlineb -c "./librenms-service.py ${DISPATCHER_ARGS}"
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/dispatcher/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/nginx/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/command/with-contenv sh

exec s6-setuidgid "${PUID}:${PGID}" nginx -g "daemon off;"
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/nginx/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/php-fpm/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/command/with-contenv sh

exec s6-setuidgid "${PUID}:${PGID}" php-fpm84 -F
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/php-fpm/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/snmpd/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/command/with-contenv sh

exec /usr/sbin/snmpd -f -Lo -c /etc/snmp/snmpd.conf
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/snmpd/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/snmptrapd/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/command/with-contenv sh

exec /usr/sbin/snmptrapd -f -Lo -m ALL -M "/opt/librenms/mibs:/opt/librenms/mibs/cisco:${SNMP_EXTRA_MIB_DIRS}" udp:162 tcp:162
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/snmptrapd/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/syslogng/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/command/with-contenv sh

exec /usr/sbin/syslog-ng -F
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/syslogng/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
3 changes: 1 addition & 2 deletions rootfs/etc/cont-init.d/03-config.sh → rootfs/etc/s6-overlay/scripts/config
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
#!/bin/bash
set -e

# From https://github.com/docker-library/mariadb/blob/master/docker-entrypoint.sh#L21-L41
Expand Down
17 changes: 4 additions & 13 deletions rootfs/etc/cont-init.d/07-svc-cron.sh → rootfs/etc/s6-overlay/scripts/config-cron
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
#!/bin/bash
set -e

CRONTAB_PATH="/var/spool/cron/crontabs"
Expand All @@ -18,7 +17,7 @@ fi

# Init
rm -rf ${CRONTAB_PATH}
mkdir -m 0644 -p ${CRONTAB_PATH}
mkdir -p ${CRONTAB_PATH}
touch ${CRONTAB_PATH}/librenms

# Cron
Expand All @@ -35,13 +34,5 @@ echo "* * * * * php /opt/librenms/artisan schedule:run --no-ansi --no-interactio

# Fix perms
echo "Fixing crontabs permissions..."
chmod -R 0644 ${CRONTAB_PATH}

# Create service
mkdir -p /etc/services.d/cron
cat >/etc/services.d/cron/run <<EOL
#!/usr/bin/execlineb -P
with-contenv
exec busybox crond -f -L /dev/stdout
EOL
chmod +x /etc/services.d/cron/run
chmod 0755 ${CRONTAB_PATH}
chmod 0644 ${CRONTAB_PATH}/librenms
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
#!/bin/bash
set -e

cd "${LIBRENMS_PATH}"

# From https://github.com/docker-library/mariadb/blob/master/docker-entrypoint.sh#L21-L41
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
Expand Down Expand Up @@ -117,14 +118,3 @@ REDIS_PASSWORD=${REDIS_PASSWORD}
REDIS_DB=${REDIS_DB}
EOL
fi

# Create service
mkdir -p /etc/services.d/dispatcher
cat >/etc/services.d/dispatcher/run <<EOL
#!/usr/bin/execlineb -P
with-contenv
s6-setuidgid ${PUID}:${PGID}
cd /opt/librenms
./librenms-service.py ${DISPATCHER_ARGS}
EOL
chmod +x /etc/services.d/dispatcher/run
31 changes: 3 additions & 28 deletions rootfs/etc/cont-init.d/04-svc-main.sh → rootfs/etc/s6-overlay/scripts/config-main
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
#!/bin/bash
set -e

cd "${LIBRENMS_PATH}"

# From https://github.com/docker-library/mariadb/blob/master/docker-entrypoint.sh#L21-L41
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
Expand Down Expand Up @@ -84,29 +85,3 @@ artisan db:seed --force --no-ansi --no-interaction
echo "Clear cache"
artisan cache:clear --no-interaction
artisan config:cache --no-interaction

mkdir -p /etc/services.d/nginx
cat >/etc/services.d/nginx/run <<EOL
#!/usr/bin/execlineb -P
with-contenv
s6-setuidgid ${PUID}:${PGID}
nginx -g "daemon off;"
EOL
chmod +x /etc/services.d/nginx/run

mkdir -p /etc/services.d/php-fpm
cat >/etc/services.d/php-fpm/run <<EOL
#!/usr/bin/execlineb -P
with-contenv
s6-setuidgid ${PUID}:${PGID}
php-fpm84 -F
EOL
chmod +x /etc/services.d/php-fpm/run

mkdir -p /etc/services.d/snmpd
cat >/etc/services.d/snmpd/run <<EOL
#!/usr/bin/execlineb -P
with-contenv
/usr/sbin/snmpd -f -c /etc/snmp/snmpd.conf
EOL
chmod +x /etc/services.d/snmpd/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/with-contenv sh
# shellcheck shell=sh
#!/bin/sh
set -e

SIDECAR_SNMPTRAPD=${SIDECAR_SNMPTRAPD:-0}
Expand Down Expand Up @@ -36,12 +35,3 @@ sed -ie "s/@SNMP_PRIV_PROTO@/${SNMP_PRIV_PROTO}/" /etc/snmp/snmptrapd.conf
sed -ie "s/@SNMP_SECURITY_LEVEL@/${SNMP_SECURITY_LEVEL}/" /etc/snmp/snmptrapd.conf
sed -ie "s/@SNMP_ENGINEID@/${SNMP_ENGINEID}/" /etc/snmp/snmptrapd.conf
sed -ie "s/@SNMP_DISABLE_AUTHORIZATION@/${SNMP_DISABLE_AUTHORIZATION}/" /etc/snmp/snmptrapd.conf

# Create service
mkdir -p /etc/services.d/snmptrapd
cat >/etc/services.d/snmptrapd/run <<EOL
#!/usr/bin/execlineb -P
with-contenv
/usr/sbin/snmptrapd -f -m ALL -M /opt/librenms/mibs:/opt/librenms/mibs/cisco:${SNMP_EXTRA_MIB_DIRS} udp:162 tcp:162
EOL
chmod +x /etc/services.d/snmptrapd/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/with-contenv sh
# shellcheck shell=sh
#!/bin/sh
set -e

SIDECAR_SYSLOGNG=${SIDECAR_SYSLOGNG:-0}
Expand All @@ -16,12 +15,3 @@ echo ">>"
mkdir -p /data/syslog-ng /run/syslog-ng
chown librenms:librenms /data/syslog-ng
chown -R librenms:librenms /run/syslog-ng

# Create service
mkdir -p /etc/services.d/syslogng
cat >/etc/services.d/syslogng/run <<EOL
#!/usr/bin/execlineb -P
with-contenv
/usr/sbin/syslog-ng -F
EOL
chmod +x /etc/services.d/syslogng/run
3 changes: 1 addition & 2 deletions rootfs/etc/cont-init.d/00-fix-logs.sh → rootfs/etc/s6-overlay/scripts/fix-logs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/with-contenv sh
# shellcheck shell=sh
#!/bin/sh

# Fix access rights to stdout and stderr
chown ${PUID}:${PGID} /proc/self/fd/1 /proc/self/fd/2 || true
3 changes: 1 addition & 2 deletions rootfs/etc/cont-init.d/02-fix-perms.sh → rootfs/etc/s6-overlay/scripts/fix-perms
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/with-contenv sh
# shellcheck shell=sh
#!/bin/sh
set -e

echo "Fixing perms..."
Expand Down
12 changes: 12 additions & 0 deletions rootfs/etc/s6-overlay/scripts/fix-uidgid
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

set -e

if [ -n "${PGID}" ] && [ "${PGID}" != "$(id -g librenms)" ]; then
echo "Switching to PGID ${PGID}..."
groupmod -o -g "${PGID}" librenms
fi
if [ -n "${PUID}" ] && [ "${PUID}" != "$(id -u librenms)" ]; then
echo "Switching to PUID ${PUID}..."
usermod -o -u "${PUID}" librenms
fi
22 changes: 22 additions & 0 deletions rootfs/etc/s6-overlay/scripts/runtime-bundles
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/command/with-contenv sh
set -eu

contents=/etc/s6-overlay/s6-rc.d/user/contents.d
mkdir -p "${contents}"
rm -f "${contents}/nginx" "${contents}/php-fpm" "${contents}/snmpd" \
"${contents}/cron" "${contents}/dispatcher" "${contents}/syslogng" \
"${contents}/snmptrapd"

if [ "${SIDECAR_DISPATCHER:-0}" = "1" ] || [ "${SIDECAR_SYSLOGNG:-0}" = "1" ] || [ "${SIDECAR_SNMPTRAPD:-0}" = "1" ]; then
if [ "${SIDECAR_DISPATCHER:-0}" = "1" ]; then
touch "${contents}/dispatcher"
fi
if [ "${SIDECAR_SYSLOGNG:-0}" = "1" ]; then
touch "${contents}/syslogng"
fi
if [ "${SIDECAR_SNMPTRAPD:-0}" = "1" ]; then
touch "${contents}/snmptrapd"
fi
else
touch "${contents}/nginx" "${contents}/php-fpm" "${contents}/snmpd" "${contents}/cron"
fi
36 changes: 36 additions & 0 deletions test/services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
set -eu

services=""
if [ "${SIDECAR_DISPATCHER:-0}" = "1" ]; then
services="$services dispatcher"
fi
if [ "${SIDECAR_SYSLOGNG:-0}" = "1" ]; then
services="$services syslogng"
fi
if [ "${SIDECAR_SNMPTRAPD:-0}" = "1" ]; then
services="$services snmptrapd"
fi
if [ -z "$services" ]; then
services="nginx php-fpm snmpd cron"
fi

for service in $services; do
s6-svwait -u -t 120000 "/run/service/$service"
test "$(s6-svstat -o up,wantedup /run/service/"$service")" = "true true"
done
for service in nginx php-fpm snmpd cron dispatcher syslogng snmptrapd; do
case " $services " in
*" $service "*) ;;
*) test "$(s6-svstat -o up,wantedup /run/service/"$service")" = "false false" ;;
esac
done
for service in $services; do
case "$service" in
nginx|php-fpm|dispatcher)
pid=$(s6-svstat -o pid /run/service/"$service")
grep -Eq "^Uid:[[:space:]]+${PUID}[[:space:]]" "/proc/${pid}/status"
grep -Eq "^Gid:[[:space:]]+${PGID}[[:space:]]" "/proc/${pid}/status"
;;
esac
done
Loading