#!/bin/sh
### BEGIN INIT INFO
# Default-Start:     3
# Default-Stop:      0 1 6
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO

PIDFILE=/var/run/ceph_rest_api.pid
mkdir -p /var/log/ceph/
LOGFILE='/var/log/ceph/ceph_rest_api'
RETVAL=0

case "$1" in
  start)
    echo "Starting ceph-rest-api python server"
    /usr/bin/ceph-rest-api -n client.admin >>$LOGFILE  &
    RETVAL=$?
    ;;
  stop)
    echo "Stopping ceph_rest_api python server" 
    ps -ef|grep -i 'ceph-rest-api'|grep python|grep -v 'grep'|tr -s ' '| awk '{print "kill -9", $2}'|sh
    ;;
  status)
    echo "ceph-rest-api status"
	ps -ef|grep -i 'ceph-rest-api'|grep python|grep -v 'grep'|tr -s ' '|wc -l | awk '{if ($1 == 0)  print "ceph-rest-api is not up"; else print "ceph-rest-api is up" }'

	;;
  *)
    echo "Usage: /etc/init.d/ceph-rest-api {start|stop|status}"
    exit 1
    ;;
esac

exit 0

