Skip to content

Commit

Permalink
Merge pull request #36 from thin-edge/add-systemd-definitions
Browse files Browse the repository at this point in the history
feat: add systemd service definitions for usage within yocto
  • Loading branch information
reubenmiller authored Nov 13, 2023
2 parents e953d59 + 605d7e4 commit 0ae834b
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 1 deletion.
1 change: 1 addition & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ if [ -n "$OUTPUT_DIR" ] && [ "$OUTPUT_DIR" != "." ] && [ "$OUTPUT_DIR" != ".." ]
fi

# Build packages for each init system
build ./packages/systemd/nfpm.yaml "$OUTPUT_DIR"
build ./packages/sysvinit/nfpm.yaml "$OUTPUT_DIR"
build ./packages/sysvinit-yocto/nfpm.yaml "$OUTPUT_DIR"
build ./packages/openrc/nfpm.yaml "$OUTPUT_DIR"
Expand Down
52 changes: 52 additions & 0 deletions packages/systemd/nfpm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# yaml-language-server: $schema=https://nfpm.goreleaser.com/static/schema.json
---
name: tedge-systemd
arch: all
platform: linux
version: ${SEMVER}
release: ${RELEASE}
section: misc
priority: optional
maintainer: thin-edge.io <thin-edge@thin-edge.io>
description: thin-edge.io systemd service definitions
vendor: thin-edge.io
homepage: https://github.com/thin-edge/thin-edge.io
license: Apache License 2.0
apk:
# Use noarch instead of "all"
arch: noarch
contents:
- src: ./services/systemd/system/*
dst: /lib/systemd/system/
file_info:
mode: 0644

- src: ./services/tedgectl
dst: /usr/bin/
file_info:
mode: 0755

- src: ./services/tedgectl_env
dst: /etc/tedgectl/env
type: config
file_info:
mode: 0644

# required otherwise the original dir permissions are overridden
- dst: /etc/tedge
type: dir
file_info:
owner: tedge
mode: 0775

# exclude as thin-edge.io support systemd out of the box
# - src: ./services/system.toml
# dst: /etc/tedge/system.toml
# type: config
# file_info:
# owner: tedge
# mode: 0644

scripts:
postinstall: ./packages/_scripts/postinstall.sh
preremove: ./packages/_scripts/preremove.sh
12 changes: 11 additions & 1 deletion services/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ generate_openrc() {
chmod a+x "openrc/init.d/$NAME"
}

generate_systemd() {
mkdir -p systemd/system
echo "[sysvinit] Generating service file: $NAME"
execute_template "systemd/service.template" > "systemd/system/$NAME.service"
chmod a+x "systemd/system/$NAME.service"
}

generate_sysvinit() {
mkdir -p sysvinit/init.d
echo "[sysvinit] Generating service file: $NAME"
Expand Down Expand Up @@ -125,7 +132,7 @@ do
SHORTNAME="${SHORTNAME:-$COMMAND}"

if [ -z "$TEMPLATE_FOR" ]; then
TEMPLATE_FOR="openrc sysvinit sysvinit s6_overlay runit supervisord"
TEMPLATE_FOR="systemd openrc sysvinit sysvinit s6_overlay runit supervisord"
fi

# Validate mandatory arguments
Expand All @@ -134,6 +141,9 @@ do

for template_name in $TEMPLATE_FOR; do
case "$template_name" in
systemd)
generate_systemd
;;
openrc)
generate_openrc
;;
Expand Down
14 changes: 14 additions & 0 deletions services/systemd/service.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=$DESCRIPTION
After=syslog.target network.target mosquitto.service

[Service]
User=$COMMAND_USER
RuntimeDirectory=$NAME
ExecStart=$COMMAND $COMMAND_ARGS
Restart=on-failure
RestartPreventExitStatus=255
RestartSec=5

[Install]
WantedBy=multi-user.target
14 changes: 14 additions & 0 deletions services/systemd/system/c8y-firmware-plugin.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Thin-edge device firmware management for Cumulocity
After=syslog.target network.target mosquitto.service

[Service]
User=tedge
RuntimeDirectory=c8y-firmware-plugin
ExecStart=/usr/bin/c8y-firmware-plugin
Restart=on-failure
RestartPreventExitStatus=255
RestartSec=5

[Install]
WantedBy=multi-user.target
14 changes: 14 additions & 0 deletions services/systemd/system/tedge-agent.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=tedge-agent is a thin-edge.io component to support operations
After=syslog.target network.target mosquitto.service

[Service]
User=tedge
RuntimeDirectory=tedge-agent
ExecStart=/usr/bin/tedge-agent
Restart=on-failure
RestartPreventExitStatus=255
RestartSec=5

[Install]
WantedBy=multi-user.target
14 changes: 14 additions & 0 deletions services/systemd/system/tedge-configuration-plugin.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Thin-edge device configuration management
After=syslog.target network.target mosquitto.service

[Service]
User=root
RuntimeDirectory=tedge-configuration-plugin
ExecStart=/usr/bin/tedge-configuration-plugin
Restart=on-failure
RestartPreventExitStatus=255
RestartSec=5

[Install]
WantedBy=multi-user.target
14 changes: 14 additions & 0 deletions services/systemd/system/tedge-log-plugin.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=thin-edge.io log file retriever
After=syslog.target network.target mosquitto.service

[Service]
User=root
RuntimeDirectory=tedge-log-plugin
ExecStart=/usr/bin/tedge-log-plugin
Restart=on-failure
RestartPreventExitStatus=255
RestartSec=5

[Install]
WantedBy=multi-user.target
14 changes: 14 additions & 0 deletions services/systemd/system/tedge-mapper-aws.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=tedge-mapper-aws checks Thin Edge JSON measurements and forwards to AWS IoT Hub
After=syslog.target network.target mosquitto.service

[Service]
User=tedge
RuntimeDirectory=tedge-mapper-aws
ExecStart=/usr/bin/tedge-mapper aws
Restart=on-failure
RestartPreventExitStatus=255
RestartSec=5

[Install]
WantedBy=multi-user.target
14 changes: 14 additions & 0 deletions services/systemd/system/tedge-mapper-az.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=tedge-mapper-az checks Thin Edge JSON measurements and forwards to Azure IoT Hub
After=syslog.target network.target mosquitto.service

[Service]
User=tedge
RuntimeDirectory=tedge-mapper-az
ExecStart=/usr/bin/tedge-mapper az
Restart=on-failure
RestartPreventExitStatus=255
RestartSec=5

[Install]
WantedBy=multi-user.target
14 changes: 14 additions & 0 deletions services/systemd/system/tedge-mapper-c8y.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=tedge-mapper-c8y converts Thin Edge JSON measurements to Cumulocity JSON format
After=syslog.target network.target mosquitto.service

[Service]
User=tedge
RuntimeDirectory=tedge-mapper-c8y
ExecStart=/usr/bin/tedge-mapper c8y
Restart=on-failure
RestartPreventExitStatus=255
RestartSec=5

[Install]
WantedBy=multi-user.target
14 changes: 14 additions & 0 deletions services/systemd/system/tedge-mapper-collectd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=tedge-mapper-collectd converts Thin Edge JSON measurements to Cumulocity JSON format
After=syslog.target network.target mosquitto.service

[Service]
User=tedge
RuntimeDirectory=tedge-mapper-collectd
ExecStart=/usr/bin/tedge-mapper collectd
Restart=on-failure
RestartPreventExitStatus=255
RestartSec=5

[Install]
WantedBy=multi-user.target

0 comments on commit 0ae834b

Please sign in to comment.