Skip to content

Instantly share code, notes, and snippets.

@lesstif
Last active Nov 19, 2016
Embed
What would you like to do?
On-Premise Edition of Sentry server(https://getsentry.com) control(start, stop, status) script on RHEL/CentOS platform.
#!/bin/sh
# Source function library.
. /etc/rc.d/init.d/functions
MASTER_PID=""
CELERY_PID=""
BEAT_PID=""
if [ ! -d log ];then
mkdir log;
fi;
##
source ~/sentry-service/bin/activate
## get process ids
getpids() {
MASTER_PID=`ps -eaf|grep sentry|grep "uWSGI master"|grep -v grep|awk '{print $2}'|paste -d " " -s`
CELERY_PID=`ps -eaf|grep sentry|grep celeryd|grep MainProcess|grep -v grep|awk '{print $2}'|paste -d" " -s`
BEAT_PID=`ps -eaf|grep sentry|grep "celery beat"|grep -v grep|awk '{print $2}'|paste -d" " -s`
}
##
killprocess() {
local PID=$1
if [ -f "/proc/${PID}/status" ];then
PNAME=`cat /proc/${PID}/status | grep Name`
else
## no such process
return;
fi
if [ ! -z ${PID} ];then
echo "sending TERM signal to '${PNAME}' ${PID}"
kill -TERM ${PID}
fi
}
start() {
##MASTER_PID=`sentry start 2>&1 | tee log/sentry-main.log &`
echo "starting sentry ...";
MASTER_PID=daemon sentry start 2>&1 | tee log/sentry-main.log &
RETVAL=$?
if [ $RETVAL != 0 ];then
echo "sentry start failed..";
exit 1;
fi
echo "starting sentry worker";
#CELERY_PID=`sentry celery worker 2>&1 | tee log/sentry-worker.log &`
CELERY_PID=daemon sentry run worker 2>&1 | tee log/sentry-worker.log &
RETVAL=$?
if [ $RETVAL != 0 ];then
echo "sentry run worker failed..";
exit 1;
fi
echo "starting sentry beat";
BEAT_PID=daemon sentry run cron 2>&1 | tee log/sentry-beat.log &
RETVAL=$?
if [ $RETVAL != 0 ];then
echo "sentry run cron failed..";
exit 1;
fi
}
stop() {
getpids
killprocess ${BEAT_PID}
killprocess ${CELERY_PID}
killprocess ${MASTER_PID}
}
status() {
getpids
if [ ! -z ${MASTER_PID} ];then
echo "Sentry master ${MASTER_PID} is running";
fi
if [ ! -z ${CELERY_PID} ];then
echo "celery worker (${CELERY_PID}) and Beat (${BEAT_PID}) is running..."
fi
}
case "$1" in
start)
start
status
;;
stop)
stop
;;
about)
ruby script/about
;;
status)
status
;;
restart)
stop
start
status
;;
*)
echo $"Usage: $0 {start|stop|restart|about|status|restart}"
RETVAL=2
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment