aboutsummaryrefslogtreecommitdiff
path: root/utils/syncthing/files/strelaysrv.init
blob: 166f4a8df33d6c8fcbdacaa8f9473a6ad1fd58b9 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh /etc/rc.common

START=90
STOP=10

USE_PROCD=1

PROG=/usr/bin/strelaysrv

config_cb() {
	[ $# -eq 0 ] && return

	option_cb() {
		local option="$1"
		local value="$2"
		case $option in
		enabled|keys|pools|status_srv)
			eval $option=$value
			;;
		_*)
			[ "$value" = "0" ] || extra_args="$extra_args -${option//_/-}"
			;;
		*)
			extra_args="$extra_args -${option//_/-}=$value"
			;;
		esac
	}

	list_cb() {
		local name="$1"
		local value="$2"
		[ "$name" = "_" ] && extra_args="$extra_args --${value//_/-}" || return 0
	}
}

service_triggers()
{
	procd_add_reload_trigger "strelaysrv"
}

start_service() {
	local pools status_srv extra_args
	# Options with default value different with the syncthing should be defined explicitly here
	local enabled=0
	local keys="/etc/strelaysrv"
	local nice=0

	config_load "strelaysrv"

	[ "$enabled" -gt 0 ] || return 0

	[ -d "$keys" ] || mkdir -p "$keys"
	[ -d "$keys" ] && chown -R nobody:nogroup "$keys"

	config_get nice strelaysrv nice "0"

	procd_open_instance
	procd_set_param command "$PROG"
	procd_append_param command -keys="$keys"

	# pools and status-srv are set to empty value by default
	procd_append_param command -pools="$pools"
	procd_append_param command -status-srv="$status_srv"
	[ -z "$extra_args" ] || procd_append_param command $extra_args

	procd_set_param nice "$nice"
	procd_set_param term_timeout 15
	procd_set_param user "nobody"
	procd_set_param respawn
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_close_instance
}

reload_service() {
	stop
	start
}