syncthing: add stdiscosrv and strelaysrv
[feed/packages.git] / utils / syncthing / files / stdiscosrv.init
1 #!/bin/sh /etc/rc.common
2
3 START=90
4 STOP=10
5
6 USE_PROCD=1
7
8 PROG=/usr/bin/stdiscosrv
9
10 config_cb() {
11 [ $# -eq 0 ] && return
12
13 option_cb() {
14 local option="$1"
15 local value="$2"
16 case $option in
17 enabled|listen|cert|db_dir|key)
18 eval $option=$value
19 ;;
20 _*)
21 [ "$value" = "0" ] || extra_args="$extra_args -${option//_/-}"
22 ;;
23 *)
24 extra_args="$extra_args -${option//_/-}=$value"
25 ;;
26 esac
27 }
28
29 list_cb() {
30 local name="$1"
31 local value="$2"
32 [ "$name" = "_" ] && extra_args="$extra_args --${value//_/-}" || return 0
33 }
34 }
35
36 service_triggers()
37 {
38 procd_add_reload_trigger "stdiscosrv"
39 }
40
41 start_service() {
42 local extra_args
43 # Options with default value different with the syncthing should be defined explicitly here
44 local enabled=0
45 local listen=":8443"
46 local cert="/etc/stdiscosrv/cert.pem"
47 local key="/etc/stdiscosrv/key.pem"
48 local db_dir="/etc/stdiscosrv/discovery.db"
49 local nice=0
50
51 config_load "stdiscosrv"
52
53 [ "$enabled" -gt 0 ] || return 0
54
55 [ -d "$db_dir" ] || mkdir -p "$db_dir"
56 [ -d "$db_dir" ] && chown -R nobody:nogroup "$db_dir"
57
58 config_get nice stdiscosrv nice "0"
59
60 procd_open_instance
61 procd_set_param command "$PROG"
62 procd_append_param command -listen="$listen"
63 procd_append_param command -db-dir="$db_dir"
64 procd_append_param command -cert="$cert"
65 procd_append_param command -key="$key"
66 [ -z "$extra_args" ] || procd_append_param command "$extra_args"
67
68 procd_set_param nice "$nice"
69 procd_set_param term_timeout 15
70 procd_set_param user "nobody"
71 procd_set_param respawn
72 procd_set_param stdout 1
73 procd_set_param stderr 1
74 procd_close_instance
75 }
76
77 reload_service() {
78 stop
79 start
80 }