#!/sbin/openrc-run

name="nginx-ui"
description="Nginx UI - Yet another WebUI for Nginx"
supervisor=supervise-daemon
pidfile="/run/${RC_SVCNAME}.pid"
command="/usr/local/bin/nginx-ui"
command_args="serve --config /usr/local/etc/nginx-ui/app.ini --pidfile ${pidfile}"
command_user="root:root"

extra_commands="status"

depend() {
    need net
    after logger firewall
    use dns
    after nginx
}

start_pre() {
    checkpath --directory --owner $command_user --mode 0755 /run
    checkpath --directory --owner $command_user --mode 0755 /usr/local/etc/nginx-ui
}

status() {
    if [ -f "${pidfile}" ]; then
        PID=$(cat "${pidfile}")
        if kill -0 $PID >/dev/null 2>&1; then
            einfo "${name} is running (PID: $PID)"
            return 0
        else
            ewarn "${name} is not running (stale PID file)"
            return 1
        fi
    else
        einfo "${name} is not running"
        return 3
    fi
}
