| 1 | #!/sbin/openrc-run |
| 2 | |
| 3 | name="KeyDB server" |
| 4 | description="High performance multithreaded fork of Redis" |
| 5 | |
| 6 | : ${cfgfile:="/etc/keydb/keydb.conf"} |
| 7 | : ${command_user:="keydb:keydb"} |
| 8 | |
| 9 | command="/usr/bin/keydb-server" |
| 10 | command_args="$cfgfile --daemonize no $command_args" |
| 11 | command_background="yes" |
| 12 | pidfile="/run/$RC_SVCNAME.pid" |
| 13 | |
| 14 | required_files="$cfgfile" |
| 15 | |
| 16 | depend() { |
| 17 | use net localmount logger |
| 18 | after keepalived firewall |
| 19 | provide redis |
| 20 | } |
| 21 | |
| 22 | start_pre() { |
| 23 | # Sets start-start-daemon's --chdir. |
| 24 | directory="$(config_get 'dir' '/var/lib/keydb')" |
| 25 | checkpath -d -o "$command_user" "$directory" || return 1 |
| 26 | |
| 27 | local logfile="$(config_get 'logfile')" |
| 28 | if [ "$logfile" ]; then |
| 29 | checkpath -f -o "$command_user" "$logfile" || return 1 |
| 30 | fi |
| 31 | |
| 32 | local unixsocket="$(config_get 'unixsocket')" |
| 33 | if [ "$unixsocket" ] && ! [ -e "${unixsocket%/*}" ]; then |
| 34 | checkpath -d -o "$command_user" "${unixsocket%/*}" || return 1 |
| 35 | fi |
| 36 | |
| 37 | return 0 |
| 38 | } |
| 39 | |
| 40 | config_get() { |
| 41 | local key="$1" |
| 42 | local default="${2:-}" |
| 43 | |
| 44 | local value="$(awk "\$1 == \"$key\" { print \$2 }" "$cfgfile")" |
| 45 | printf '%s\n' "${value:-$default}" |
| 46 | } |