#!/bin/sh
### BEGIN INIT INFO
# Provides:          odoo-server
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      $network
# Should-Stop:       $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Enterprise Business Applications
# Description:       ODOO Business Applications
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
DAEMON="/odoo/venv/bin/python3"
DAEMON_OPTS="/odoo/odoo-server/odoo-bin -c /etc/odoo-server.conf"
NAME=odoo-server
DESC=Odoo
PIDFILE=/var/run/${NAME}.pid
USER=odoo

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

case "$1" in
start)
    echo "Starting $DESC"
    start-stop-daemon --start --quiet --background --make-pidfile \
        --pidfile $PIDFILE \
        --chuid $USER \
        --exec $DAEMON -- $DAEMON_OPTS
    echo "$NAME started"
    ;;
stop)
    echo "Stopping $DESC"
    start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo
    echo "$NAME stopped"
    ;;
restart)
    echo "Restarting $DESC"
    $0 stop
    sleep 1
    $0 start
    ;;
status)
    status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
    ;;
*)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac

exit 0