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
37 changes: 21 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

steps:
- name: "Check out NIPAP repository"
uses: actions/checkout@v2
uses: actions/checkout@v7

- name: "Install dependencies and prepare NIPAP"
run: |
Expand Down Expand Up @@ -175,41 +175,46 @@ jobs:
docker:
name: docker
runs-on: ubuntu-24.04
env:
PUBLISH_DOCKER: >-
${{ github.repository == 'SpriteLink/NIPAP' &&
github.event_name == 'push' &&
github.ref == 'refs/heads/master' }}
steps:

- name: "Set up QEMU"
uses: docker/setup-qemu-action@v3
uses: docker/setup-qemu-action@v4

- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@v4

- name: "Check out NIPAP repository"
uses: actions/checkout@v2
uses: actions/checkout@v7

- name: "Hadolint nipapd"
uses: hadolint/hadolint-action@v3.1.0
uses: hadolint/hadolint-action@v3.5.0
with:
dockerfile: Dockerfile.nipapd
failure-threshold: warning
override-info: DL3013

- name: "Hadolint WWW"
uses: hadolint/hadolint-action@v3.1.0
uses: hadolint/hadolint-action@v3.5.0
with:
dockerfile: Dockerfile.www
failure-threshold: warning
override-info: DL3013

- name: "nipapd metadata"
id: nipapd_meta
uses: docker/metadata-action@v5
uses: docker/metadata-action@v6
with:
images: ${{ env.NIPAPD_IMAGE }}
tags: |
type=sha,prefix=

- name: "Build nipapd Docker image"
uses: docker/build-push-action@v5
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile.nipapd
Expand All @@ -221,14 +226,14 @@ jobs:

- name: "www metadata"
id: www_meta
uses: docker/metadata-action@v5
uses: docker/metadata-action@v6
with:
images: ${{ env.WWW_IMAGE }}
tags: |
type=sha,prefix=

- name: "Build www Docker image"
uses: docker/build-push-action@v5
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile.www
Expand Down Expand Up @@ -277,15 +282,15 @@ jobs:
nosetests3 tests/test_rest.py

- name: "Login to Docker Hub"
if: ${{ github.ref_name == 'master' }}
uses: docker/login-action@v3
if: ${{ env.PUBLISH_DOCKER == 'true' }}
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: "Build and push nipapd Docker image"
if: ${{ github.ref_name == 'master' }}
uses: docker/build-push-action@v5
if: ${{ env.PUBLISH_DOCKER == 'true' }}
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile.nipapd
Expand All @@ -294,8 +299,8 @@ jobs:
push: true

- name: "Build and push www Docker image"
if: ${{ github.ref_name == 'master' }}
uses: docker/build-push-action@v5
if: ${{ env.PUBLISH_DOCKER == 'true' }}
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile.www
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile.www
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

ENV DEBIAN_FRONTEND=noninteractive

ENV NIPAPD_HOST=nipapd NIPAPD_PORT=1337 WWW_USERNAME=guest WWW_PASSWORD=guest
ENV NIPAPD_HOST=nipapd NIPAPD_PORT=1337
# hadolint ignore=DL3064
ENV WWW_USERNAME=guest WWW_PASSWORD=guest

Check warning on line 34 in Dockerfile.www

View workflow job for this annotation

GitHub Actions / docker

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "WWW_PASSWORD") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

# apt update, upgrade & install packages
RUN apt-get update -qy && apt-get upgrade -qy \
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ buildrpm:

builddeb:
for PROJ in $(SUBPROJ); do \
cd $$PROJ; make builddeb; cd ..; \
$(MAKE) -C $$PROJ builddeb || exit $$?; \
done

ifeq ($(CURBRANCH), $(shell echo -n 'gh-pages'))
Expand Down
6 changes: 4 additions & 2 deletions nipap/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ Priority: optional
Build-Depends: debhelper-compat (= 13),
dh-python,
python3-all,
python3-setuptools
python3-setuptools,
python3-docutils,
pybuild-plugin-pyproject
Standards-Version: 4.6.1
Homepage: https://spritelink.github.io/NIPAP/
Rules-Requires-Root: no

Package: nipap-common
Architecture: all
Multi-Arch: foreign
Depends: ${misc:Depends}, ${python3:Depends}
Depends: ${misc:Depends}, ${python3:Depends}, python3-pkg-resources
Suggests: python3-ldap
Description: Neat IP Address Planner
The Neat IP Address Planner, NIPAP, is a system built for efficiently managing
Expand Down
11 changes: 8 additions & 3 deletions nipap/debian/nipapd.init
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CONFIGFILE=/etc/nipap/nipap.conf
NAME=NIPAPd
PIDFILE=/var/run/nipap/nipapd.pid
PIDDIR=`dirname $PIDFILE`
DAEMON_NAME=nipapd

. /lib/lsb/init-functions

Expand Down Expand Up @@ -46,6 +47,10 @@ running() {
chown nipap:nipap $PIDDIR
fi

# Older daemon versions created the PID file with mode 0666.
if [ -f "$PIDFILE" ] && [ "$(stat -c %a "$PIDFILE")" != "644" ]; then
chmod 0644 "$PIDFILE"
fi
if [ $(flock -xn $PIDFILE -c 'echo 1' 2> /dev/null) ]; then
echo -n
rm -f $PIDFILE > /dev/null 2>&1
Expand Down Expand Up @@ -74,7 +79,7 @@ case "$1" in
log_daemon_msg "Stopping NIPAPd XML-RPC server" "nipapd"
RUNNING=$(running)
if [ -n "$RUNNING" ]; then
if start-stop-daemon --stop --pidfile $PIDFILE --retry 30; then
if start-stop-daemon --stop --name $DAEMON_NAME --pidfile $PIDFILE --retry 30; then
log_end_msg 0
else
log_end_msg 1
Expand All @@ -87,7 +92,7 @@ case "$1" in
log_daemon_msg "Reloading NIPAPd XML-RPC server's configuration" "nipapd"
RUNNING=$(running)
if [ -n "$RUNNING" ]; then
if start-stop-daemon --stop --signal HUP --pidfile $PIDFILE; then
if start-stop-daemon --stop --name $DAEMON_NAME --signal HUP --pidfile $PIDFILE; then
log_end_msg 0
else
log_end_msg 1
Expand All @@ -103,7 +108,7 @@ case "$1" in
log_daemon_msg "Restarting NIPAPd XML-RPC server" "nipapd"
RUNNING=$(running)
if [ -n "$RUNNING" ]; then
if start-stop-daemon --stop --pidfile $PIDFILE; then
if start-stop-daemon --stop --name $DAEMON_NAME --pidfile $PIDFILE --retry 30; then
if start-stop-daemon --start --exec $DAEMON -- -c $CONFIGFILE $ARGS; then
log_end_msg 0
else
Expand Down
1 change: 1 addition & 0 deletions nipap/debian/nipapd.install
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ usr/share/nipap
usr/share/nipap/nipap.conf.dist etc/nipap
usr/share/man/man8/nipapd.8
usr/share/man/man1/nipap-passwd.1
debian/nipapd.service.d/*.conf usr/lib/systemd/system/nipapd.service.d
3 changes: 3 additions & 0 deletions nipap/debian/nipapd.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ case "$1" in

db_stop

if [ -d /run/systemd/system ]; then
systemctl daemon-reload
fi
# finally start nipapd
invoke-rc.d nipapd start
;;
Expand Down
3 changes: 3 additions & 0 deletions nipap/debian/nipapd.service.d/stop.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Service]
KillMode=control-group
TimeoutStopSec=70s
5 changes: 5 additions & 0 deletions nipap/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
# This file was automatically generated by stdeb 0.6.0+git at
# Tue, 18 Oct 2011 21:55:07 +0200
export DH_VERBOSE=1
export PYBUILD_SYSTEM=pyproject

%:
dh $@ --with python3 --buildsystem=pybuild

override_dh_auto_build:
$(MAKE) sql2py
dh_auto_build
18 changes: 11 additions & 7 deletions nipap/nipap/nipapd.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ def exit_cleanup():
except psutil.NoSuchProcess:
return

children = p.children

for pid in children(recursive=True):
os.kill(pid.pid, signal.SIGTERM)
for child in p.children(recursive=True):
try:
os.kill(child.pid, signal.SIGTERM)
except ProcessLookupError:
# A child may already have exited during shutdown.
pass


@atexit.register
Expand All @@ -55,9 +57,9 @@ def at_exit():
def handle_sigterm(sig, frame):
""" Handle SIGTERM
"""
exit_cleanup()
# and make a clean exit ourselves
# sys.exit(0)
# Let atexit clean up children, and avoid re-entering during shutdown.
signal.signal(signal.SIGTERM, signal.SIG_IGN)
sys.exit(0)


# register signal handler for SIGTERM
Expand Down Expand Up @@ -260,6 +262,8 @@ def run():
except IOError:
logger.error('NIPAPd already running (pid: ' + lf.read().strip() + ')')
sys.exit(1)
# Daemonization resets umask; restrict PID file writes to its owner.
os.fchmod(lf.fileno(), 0o644)
logger.debug('Writing PID to file: ' + cfg.get('nipapd', 'pid_file'))
lf.truncate(0)
lf.write('%d\n' % os.getpid())
Expand Down
1 change: 1 addition & 0 deletions nipap/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def get_data_files():
'sql/upgrade-4-5.plsql',
'sql/upgrade-5-6.plsql',
'sql/upgrade-6-7.plsql',
'sql/upgrade-7-8.plsql',
'sql/functions.plsql',
'sql/triggers.plsql',
'sql/ip_net.plsql',
Expand Down