summaryrefslogtreecommitdiffstats
path: root/net/ripe-atlas/files/ripe-atlas.init
blob: 25512fa723460d350b60e86fc5d1ba90a74299ba (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/sh /etc/rc.common
START=60
STOP=01
USE_PROCD=1
MAINU=ripe-atlas
MEASU=ripe-atlas
GROUP=ripe-atlas

validate_config()
{
	uci_load_validate 'ripe-atlas' 'ripe-atlas' "${1}" "${2}" \
		'enabled:uinteger:1' \
		'log_stderr:uinteger:0' \
		'log_stdout:uinteger:0' \
		'mode:string:prod' \
		'rxtx_report:uinteger:0'
}

create_dir()
{
	local user
	local group
	local mode
	local dir

	user="${1}"
	shift
	group="${1}"
	shift
	mode="${1}"
	shift

	while [ -n "${1}" ]; do
		dir="${1}"
		mkdir -p "${dir}"
		chown ${user}:${group} "${dir}"
		chmod ${mode} "${dir}"
		shift
	done
}

setup_environment()
{
	create_dir ${MEASU} ${GROUP} 0775 \
		/var/run/ripe-atlas/pids \
		/var/run/ripe-atlas/status
	create_dir ${MEASU} ${GROUP} 2775 \
		/var/spool/ripe-atlas/crons \
		/var/spool/ripe-atlas/crons/main \
		/var/spool/ripe-atlas/crons/2 \
		/var/spool/ripe-atlas/crons/3 \
		/var/spool/ripe-atlas/crons/4 \
		/var/spool/ripe-atlas/crons/5 \
		/var/spool/ripe-atlas/crons/6 \
		/var/spool/ripe-atlas/crons/7 \
		/var/spool/ripe-atlas/crons/8 \
		/var/spool/ripe-atlas/crons/9 \
		/var/spool/ripe-atlas/crons/10 \
		/var/spool/ripe-atlas/crons/11 \
		/var/spool/ripe-atlas/crons/12 \
		/var/spool/ripe-atlas/crons/13 \
		/var/spool/ripe-atlas/crons/14 \
		/var/spool/ripe-atlas/crons/15 \
		/var/spool/ripe-atlas/crons/16 \
		/var/spool/ripe-atlas/crons/17 \
		/var/spool/ripe-atlas/crons/18 \
		/var/spool/ripe-atlas/crons/19 \
		/var/spool/ripe-atlas/crons/20 \
		/var/spool/ripe-atlas/data \
		/var/spool/ripe-atlas/data/new \
		/var/spool/ripe-atlas/data/oneoff \
		/var/spool/ripe-atlas/data/out \
		/var/spool/ripe-atlas/data/out/ooq \
		/var/spool/ripe-atlas/data/out/ooq10
}

start_instance()
{
	local cfg=/etc/ripe-atlas/config.txt
	local mod=/etc/ripe-atlas/mode

	if [ ${2} -ne 0 ]; then
		echo 'validation failed'
		return 1
	fi

	if [ ${enabled} -eq 0 ]; then
		return 1
	fi

	rm -f /etc/ripe-atlas/reg_servers.sh
	case "${mode}" in
		test|dev|prod)
			;;
		*)
			return 1
			;;
	esac

	echo 'Starting RIPE Atlas'
	setup_environment
	: > "${cfg}"

	if [ ${rxtx_report} -ne 0 ]; then
		echo 'RXTXRPT=yes' >> "${cfg}"
	fi
	echo "${mode}" > "${mod}"

	procd_open_instance
	procd_set_param command /usr/sbin/ripe-atlas
	procd_set_param user ${MAINU}
	procd_set_param group ${GROUP}
	procd_set_param stdout ${log_stdout}
	procd_set_param stderr ${log_stderr}
	procd_set_param respawn
	if [ -x /sbin/ujail ]; then
		procd_add_jail ripe-atlas
		procd_append_param capabilities /usr/share/ripe-atlas/capabilities.json
	fi
	procd_close_instance

	return 0
}

start_service()
{
	config_load 'ripe-atlas'
	config_foreach validate_config 'ripe-atlas' start_instance
}

stop_service()
{
	local pids
	local pid

	for pid in $(find /proc -type d -maxdepth 1 -group ${GROUP} -print); do
		pids="${pid##*/} ${pids}"
	done

	if [ -n "${pids}" ]; then
		kill ${pids} 1>/dev/null 2>&1
	fi
}

service_triggers()
{
	procd_add_validation validate_config
}