Skip to content

Commit

Permalink
First shot at creating a Debian service
Browse files Browse the repository at this point in the history
  • Loading branch information
mthmulders committed Aug 10, 2023
1 parent 56955f8 commit 09e8718
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ license = "MIT License"

[package.metadata.deb]
maintainer = "Maarten Mulders"
maintainer-scripts = "debian/"
copyright = "2021 - 2023 Maarten Mulders"

[package.metadata.deb.systemd-units]


[dependencies]
config = "0.13.3"
log = "0.4.19"
Expand Down
49 changes: 49 additions & 0 deletions debian/postinst
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#
9 changes: 9 additions & 0 deletions debian/service
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

0 comments on commit 09e8718

Please sign in to comment.