-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First shot at creating a Debian service
- Loading branch information
1 parent
56955f8
commit 09e8718
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Inspired by https://github.com/NLnetLabs/krill/blob/main/pkg/debian/postinst | ||
|
||
#!/bin/sh | ||
set -e | ||
|
||
PKG_CONF="/etc/dsmr-rs.conf" | ||
PKG_CONF_PERMS=640 | ||
PKG_USER="dsmr-rs" | ||
|
||
create_user() { | ||
if id ${PKG_USER} > /dev/null 2>&1; then return; fi | ||
adduser --system --no-create-home --group ${PKG_USER} | ||
} | ||
|
||
create_configuration() { | ||
if [ ! -f "${PKG_CONF}" ]; then | ||
cat <<EOF > ${PKG_CONF} | ||
# The DSMR-reader API to forward telegrams to | ||
DATALOGGER_API_HOSTS=https://my.host.name | ||
|
||
# The serial port to read telegrams from | ||
DATALOGGER_SERIAL_PORT=/dev/ttyUSB0 | ||
|
||
# The API key to authenticate against the DSMR-reader API | ||
DATALOGGER_API_KEYS=something-secret | ||
|
||
# The input method for reading telegrams. Expected to always be 'serial', so effectively ignored. | ||
DATALOGGER_INPUT_METHOD=serial | ||
|
||
# Baudrate for reading telegrams from the serial line. | ||
DATALOGGER_SERIAL_BAUDRATE=9600 | ||
|
||
EOF | ||
# Ensure that the config file has the correct ownership | ||
chown ${PKG_USER}:${PKG_USER} ${PKG_CONF} | ||
|
||
# Ensure that the config file has the correct permissions | ||
chmod ${PKG_CONF_PERMS} ${PKG_CONF} | ||
fi | ||
} | ||
|
||
case "$1" in | ||
configure) | ||
create_user | ||
create_configuration | ||
;; | ||
esac | ||
|
||
#DEBHELPER# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Unit] | ||
Description=dsmr-rs | ||
|
||
[Service] | ||
EnvironmentFile=/etc/dsmr-rs.conf | ||
ExecStart=/usr/bin/dsmr-rs | ||
|
||
[Install] | ||
WantedBy=multi-user.target |