#!/bin/sh
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

### BEGIN INIT INFO
# Provides:          plinth
# Required-Start:    $network $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: plinth web frontend
# Description:
#   Control the plinth web frontend.
### END INIT INFO

# This file is /etc/init.d/plinth

DESC="embedded web frontend"
NAME=plinth

DAEMON=/usr/bin/plinth
PID_FILE=/var/run/plinth.pid
SERVER_DIR=/plinth

PLINTH_USER=plinth
PLINTH_GROUP=plinth

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

case "$1" in
    start)
        log_daemon_msg "Starting $DESC" "$NAME"
        start_daemon -p $PID_FILE $DAEMON --pidfile=$PID_FILE \
            --server_dir=$SERVER_DIR
        log_end_msg $?
        ;;
    stop)
        log_daemon_msg "Stopping $DESC" "$NAME"
        killproc -p $PID_FILE $DAEMON
        RETVAL=$?
        [ $RETVAL -eq 0 ] && [ -e "$PID_FILE" ] && rm -f $PID_FILE
        log_end_msg $RETVAL
        ;;
    restart|force-reload)
        $0 stop
        $0 start
        ;;
    status)
        status_of_proc -p $PID_FILE "$DAEMON" plinth && exit 0 || exit $?
        ;;
    *)
        echo "Usage: $NAME {start|stop|restart|force-reload|status}" >&2
        exit 1
        ;;
esac
