Last active
November 19, 2016 11:26
-
-
Save lesstif/96d2694d178e910a53f8d217c82b28e2 to your computer and use it in GitHub Desktop.
On-Premise Edition of Sentry server(https://getsentry.com) control(start, stop, status) script on RHEL/CentOS platform.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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