aboutsummaryrefslogtreecommitdiffstats
path: root/main/redis/redis.initd
blob: f617e005ff6c411c35fd18ec94706db9047717c3 (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
#!/sbin/openrc-run

name="Redis server"

: ${cfgfile:=${REDIS_CONF:-"/etc/redis.conf"}}
: ${command_user:="${REDIS_USER:-redis}:${REDIS_GROUP:-redis}"}
: ${retry:=30}

command="/usr/bin/redis-server"
command_args="$cfgfile --daemonize no $command_args"
command_background="yes"
pidfile="/run/$RC_SVCNAME.pid"

required_files="$cfgfile"

depend() {
	use net localmount logger
	after keepalived firewall
}

start_pre() {
	# Sets start-start-daemon's --chdir.
	directory=$(config_get 'dir' '/var/lib/redis')
	checkpath -d -o "$command_user" "$directory"

	local logfile=$(config_get 'logfile')
	[ "$logfile" ] && checkpath -d -o "$command_user" "${logfile%/*}"

	local unixsocket=$(config_get 'unixsocket')
	[ "$unixsocket" ] && checkpath -d -o "$command_user" "${unixsocket%/*}"

	return 0
}

config_get() {
	local key="$1"
	local default="${2:-}"

	local value=$(awk "\$1 == \"$key\" { print \$2 }" "$cfgfile")
	printf '%s\n' "${value:-$default}"
}