aboutsummaryrefslogtreecommitdiffstats
path: root/main/mqtt-exec/mqtt-exec.initd
blob: 4b6b2c9627ea2caa02df5492c9bf3cde923e23ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/sbin/openrc-run

: ${mqtt_broker:="msg.alpinelinux.org"}
: ${mqtt_topics:="git/aports/$git_branch"}
: ${exec_user:=nobody}

command=/usr/bin/mqtt-exec
pidfile=/var/run/$SVCNAME/mqtt-exec.pid

depend() {
	need localmount net
	after firewall
}

start() {
	local topic
	checkpath --directory --owner ${exec_user:-nobody} ${pidfile%/*}
	set -- $command_args -h ${mqtt_broker} -v
	for topic in $mqtt_topics; do
		set -- "$@" -t "$topic"
	done

	if [ -n "$will_topic" ]; then
		set -- "$@" --will-topic "$will_topic"
	fi
	if yesno "$will_retain"; then
		set -- "$@" --will-retain
	fi
	if [ -n "$will_payload" ]; then
		set -- "$@" --will-payload "$will_payload"
	fi
	if [ -n "$will_qos" ]; then
		set -- "$@" --will-qos "$will_qos"
	fi

	ebegin "Starting $SVCNAME"
	start-stop-daemon --start --stdout /dev/null --stderr /dev/null \
		--background --make-pid --user ${exec_user} \
		--pidfile ${pidfile} \
		--exec $command \
		-- "$@" \
		-- ${exec_command}
	eend
}