aboutsummaryrefslogtreecommitdiff
path: root/net/vallumd/files/vallumd.init
blob: f9ff608362765374e4bec21f55a3c2b46d571a66 (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
#!/bin/sh /etc/rc.common

START=99
USE_PROCD=1
PROG=/usr/sbin/vallumd

add_topic() {
	procd_append_param command -t "$1"
}

start_service() {
	local enabled mqtt_ca mqtt_host mqtt_pass mqtt_port mqtt_tls mqtt_user

	config_load "vallumd"
	config_get_bool enabled "mqtt" "enabled" 1
	[ "$enabled" -gt 0 ] || return 1

	config_get mqtt_ca "mqtt" "ca"
	config_get mqtt_host "mqtt" "host"
	config_get mqtt_pass "mqtt" "pass"
	config_get mqtt_port "mqtt" "port"
	config_get mqtt_tls "mqtt" "tls"
	config_get mqtt_user "mqtt" "user"

	procd_open_instance

	procd_set_param command $PROG

	[ -n "$mqtt_host" ] && procd_append_param command -h "$mqtt_host"
	[ -n "$mqtt_pass" ] && procd_append_param command -P "$mqtt_pass"
	[ -n "$mqtt_port" ] && procd_append_param command -p "$mqtt_port"
	[ -n "$mqtt_user" ] && procd_append_param command -u "$mqtt_user"
	[ $mqtt_tls -gt 0 ] && procd_append_param command -T -c "$mqtt_ca"
	config_list_foreach mqtt topics add_topic

	procd_set_param respawn

	procd_close_instance
}