#!/bin/sh

# Author: Jonathan Field - World Possible
#
# /etc/init.d/kiwix

### BEGIN INIT INFO
# Provides:          kiwix
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: kiwix server, browse installed RACHEL zim files on port 81
### END INIT INFO

set -e

# we let the www user restart kiwix
#if !(whoami | grep "root" -q)
#then
#	echo "You need to be root"
#	exit 1
#fi

PATH=/bin:/usr/bin:/sbin:/usr/sbin

case "$1" in
  start)
    /var/kiwix/bin/rachel-kiwix-start.pl
    ;;
  stop)
    killall kiwix-serve
    ;;
  restart)
    # it kills the old process itself
    /var/kiwix/bin/rachel-kiwix-start.pl
    ;;
  status)
    ps aux | grep kiwix-serve | grep -v grep
    ;;
  *)
    # log_success_msg wasn't working - replaced with echo
    echo "Usage: /etc/init.d/kiwix {start|stop|restart|status}"
    exit 1
esac

