summaryrefslogtreecommitdiff
blob: c87f6576d6bf290d93698c682e552873c534e0a3 (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
#!/sbin/openrc-run
# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

TJ_NAME=${SVCNAME##*.}
if [ -n "${TJ_NAME}" -a "${SVCNAME}" != "trojan" ]; then
	TJ_PIDFILE="/run/trojan.${TJ_NAME}.pid"
	TJ_CONFIG="/etc/trojan/${TJ_NAME}.json"
	TJ_LOG="/var/log/trojan.${TJ_NAME}.log"
else
	TJ_PIDFILE="/run/trojan.pid"
	TJ_CONFIG="/etc/trojan/config.json"
	TJ_LOG="/var/log/trojan.log"
fi

depend() {
	need net
}

start() {
	ebegin "Starting Trojan, Log File: ${TJ_LOG}"
	start-stop-daemon --start -b \
		--user nobody --group nobody \
		-1 "${TJ_LOG}" -2 "${TJ_LOG}" \
		-m -p "${TJ_PIDFILE}" \
		--exec /usr/bin/trojan  -- "${TJ_CONFIG}"
	eend $?
}

stop() {
	ebegin "Stopping Trojan"
	start-stop-daemon --stop \
		--user nobody --group nobody \
		-p "${TJ_PIDFILE}"
	eend $?
}