#!/bin/bash # chkconfig: 2345 55 25 # description: Elastic Drive startup script # Modified on 7/31/2007 # this is variables declaration BASEDIR=`dirname $0` PID=`cat "$BASEDIR/elasticdrive.pid"` # this is control code if [[ "$1" == "help" ]]; then help_ed fi if [[ "$1" == "restart" ]] && [[ -e "$BASEDIR/elasticdrive.pid" ]]; then restart_ed exit $? elif [[ "$1" == "restart" ]];then echo "Cannot stop elasticdrive. Not running." exit 1 fi if [[ -e $BASEDIR/elasticdrive.pid ]] && [[ -e "$BASEDIR/elasticdrive.pid" ]]; then if [[ "$1" == "stop" ]];then stop_ed else echo "Elastic drive is already running with PID:`cat $BASEDIR/elasticdrive.pid`" echo "If this is a stale PID, just delete the file." exit 1 fi fi # this is library of functions function start_ed { if check_ids ; then "$BASEDIR/elasticdrive" start python "$BASEDIR/s3_nbd_server.pyc" 2>>$BASEDIR/logs/elasticdrive.log 1>>$BASEDIR/logs/elasticdrive.log & PID$ echo $PID > "$BASEDIR/elasticdrive.pid" echo "Started elasticdrive as pid $PID" exit 0 else echo "Please enter your access id information in config.ini \n see AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY"; exit 1 fi } function stop_ed { echo "Killing $PID" kill $PID rm "$BASEDIR/elasticdrive.pid" exit 0 } function restart_ed { stop_ed start_ed exit 0 } function help_ed { echo "Usage: elasticdrive [start|stop|restart]" exit 1 } function check_ids { # get file handle if [[ -e "$BASEDIR/config.ini" ]]; then echo "File config.ini is not found in $BASEDIR ! Exiting setup..." exit 0 else # check whether ids are present if grep 'XXXX' $BASEDIR/config.ini; then exit 0 else exit 1 fi fi } start_ed