Add systemd unit files
Largely inspired by https://lwn.net/Articles/584175/ "They must be suitable for every distribution to use." Packagers must define: - ExecStart=/path/to/bip_env.sh - Environment=BIP_DEFAULT_CONFIG='/path/to/default/bip' using a unit file drop-in bip-config.service.d/<distrib>.conf
This commit is contained in:
parent
554c372452
commit
3f4a260a54
@ -24,4 +24,5 @@ dist_examples_DATA = samples/bip.conf samples/bip.vim
|
||||
EXTRA_DIST = \
|
||||
BUGS \
|
||||
scripts/bip-release \
|
||||
scripts/bipgenconfig
|
||||
scripts/bipgenconfig \
|
||||
systemd
|
||||
|
20
systemd/README
Normal file
20
systemd/README
Normal file
@ -0,0 +1,20 @@
|
||||
Notes about systemd unit files for bip.
|
||||
|
||||
Distro specific commandline configuration is provided by installing a script
|
||||
named. A default script named bip_env.sh is provided.
|
||||
|
||||
This should write /run/sysconfig/bip based on configuration
|
||||
information such as in /etc/sysconfig/bip or /etc/defaults/bip. It is run once
|
||||
by bip-config.service.
|
||||
|
||||
Distro specific path for bip_env.sh script must be set using a
|
||||
bip-config.service.d/distrib.conf unit file drop-in:
|
||||
[Service]
|
||||
ExecStart=/path/to/bip_env.sh
|
||||
|
||||
bip_env.sh try some default paths for the default configuration file: either
|
||||
/etc/default/bip or /etc/sysconfig/bip.
|
||||
Optionaly, the default configuration file path can be set too:
|
||||
[Service]
|
||||
ExecStart=/path/to/bip_env.sh
|
||||
Environment=BIP_DEFAULT_CONFIG='/path/to/default/bip'
|
12
systemd/bip-config.service
Normal file
12
systemd/bip-config.service
Normal file
@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Preprocess Bip configuration
|
||||
After=local-fs.target
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=no
|
||||
# Packagers must define:
|
||||
# - ExecStart=/path/to/bip_env.sh
|
||||
# - Environment='BIP_DEFAULT_CONFIG=/path/to/default/bip'
|
||||
# using a unit file drop-in bip-config.service.d/<distrib>.conf
|
23
systemd/bip.service
Normal file
23
systemd/bip.service
Normal file
@ -0,0 +1,23 @@
|
||||
[Unit]
|
||||
Description=Bip IRC Proxy
|
||||
Requires=network.target
|
||||
|
||||
Wants=bip-config.service
|
||||
After=bip-config.service
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=/run/sysconfig/bip
|
||||
|
||||
Type=forking
|
||||
User=bip
|
||||
Group=bip
|
||||
ExecStartPre=/bin/sh -c '[ $ENABLED != 0 ]'
|
||||
ExecStart=/usr/bin/bip $DAEMON_ARGS
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
RuntimeDirectory=bip
|
||||
RuntimeDirectoryMode=0750
|
||||
KillMode=process
|
||||
Restart=on-abnormal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
40
systemd/bip_env.sh
Executable file
40
systemd/bip_env.sh
Executable file
@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
# Create /run/sysconfig/bip from default configuration file, for
|
||||
# bip-config.service
|
||||
|
||||
# BIP_DEFAULT_CONFIG environment variable can be defined by packagers in a
|
||||
# drop-in override of bip-config.service unit
|
||||
if [ -n "${BIP_DEFAULT_CONFIG}" ]; then
|
||||
# try some default paths
|
||||
if [ -r /etc/default/bip ]; then
|
||||
BIP_DEFAULT_CONFIG=/etc/default/bip
|
||||
. "${BIP_DEFAULT_CONFIG}"
|
||||
elif [ -r /etc/sysconfig/bip ]; then
|
||||
BIP_DEFAULT_CONFIG=/etc/sysconfig/bip
|
||||
. "${BIP_DEFAULT_CONFIG}"
|
||||
fi
|
||||
else
|
||||
. "${BIP_DEFAULT_CONFIG}"
|
||||
fi
|
||||
|
||||
ENABLED=${ENABLED:-1}
|
||||
|
||||
mkdir -p /run/sysconfig
|
||||
{
|
||||
echo ENABLED=${ENABLED}
|
||||
DAEMON_HOME=${DAEMON_HOME:-/var/lib/bip}
|
||||
DAEMON_CONFIG=${DAEMON_CONFIG:-/etc/bip/bip.conf}
|
||||
echo "DAEMON_ARGS=${DAEMON_ARGS:--f '${DAEMON_CONFIG}' -s '${DAEMON_HOME}'}"
|
||||
} > /run/sysconfig/bip
|
||||
|
||||
if [ ${ENABLED} = 0 ]; then
|
||||
echo "INFO: BIP is explicitely disabled (ENABLED == 0) in" \
|
||||
"'${BIP_DEFAULT_CONFIG}'."
|
||||
else
|
||||
if [ -n "${DAEMON_USER}" -o -n "${DAEMON_GROUP}" ]; then
|
||||
echo "ERROR: Using systemd, DAEMON_USER and DAEMON_GROUP could not" \
|
||||
"be defined using the default configuration file. A drop-in" \
|
||||
"override of bip-config.service unit need to be created instead."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
Loading…
x
Reference in New Issue
Block a user