Last active
February 9, 2016 05:08
-
-
Save thanad/18a41f3fdfd61b617c16 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
| # /etc/init.d/sentry | |
| # A debian-compatible sentry startup script | |
| # | |
| ### BEGIN INIT INFO | |
| # Provides: sentry | |
| # Required-Start: $remote_fs $syslog $network | |
| # Required-Stop: $remote_fs $syslog $network | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Short-Description: Start Sentry at boot time | |
| # Description: Controls the sentry aggregate logging engine. | |
| ### END INIT INFO | |
| # | |
| # Specify some important information | |
| # | |
| PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
| DESC="Sentry aggregate logging system" | |
| NAME=sentry | |
| SCRIPTNAME=$0 | |
| SETSID=/usr/bin/setsid | |
| SENTRY=/opt/sentry/bin/sentry | |
| SENTRY_CONF=/home/maqe/.sentry | |
| SENTRY_LOG=/var/log/sentry.log | |
| SENTRY_USER=maqe | |
| SU=/bin/su | |
| # Ensure the setsid program exists | |
| [ -x "$SETSID" ] || (echo "setsid package not installed" && exit 0) | |
| # Make sure we run as root | |
| [ `id -u` -ne 0 ] && (echo "The $1 init script can only be run as root" && exit 1) | |
| # | |
| # Determines whether or not the service is running | |
| # | |
| get_pid() { | |
| echo $(ps auxw | grep gunicorn | grep master | grep -oP "^[^0-9]+([0-9]+)" | grep -oP "[0-9]+") | |
| } | |
| # | |
| # Handles starting the sentry service and ensuring that it started correctly and | |
| # without problems. | |
| # | |
| start() { | |
| PID=$(get_pid) | |
| [ "$PID" ] && (echo "Sentry is already running" && return 1) | |
| mkdir $(dirname $SENTRY_LOG) > /dev/null 2>&1 || true | |
| chown $SENTRY_USER $SENTRY_LOG | |
| $SU -l $SENTRY_USER --shell=/bin/bash -c "$SETSID $SENTRY --config=$SENTRY_CONF start &> $SENTRY_LOG &" || return 2 | |
| #setsid /srv/sentry/bin/sentry --config=/etc/sentry/sentry.conf.py start &> sentry.log | |
| } | |
| # | |
| # Handles terminating the sentry service and ensuring that it terminated | |
| # correctly. | |
| # | |
| stop() { | |
| PID=$(get_pid) | |
| [ "$PID" ] && (kill $PID || return 3) | |
| } | |
| # | |
| # Determines whether or not the service is running | |
| # | |
| status() { | |
| PID=$(get_pid) | |
| if [ "$PID" ]; then | |
| echo "Sentry is running" | |
| else | |
| echo "Sentry is stopped" | |
| fi | |
| } | |
| # | |
| # Deal with the request | |
| # | |
| case "$1" in | |
| start) | |
| echo "Starting sentry" | |
| start | |
| ;; | |
| stop) | |
| echo "Stopping sentry" | |
| stop | |
| ;; | |
| status) | |
| status | |
| ;; | |
| *) | |
| echo "Usage: $0 {start|stop|status}" | |
| exit 1 | |
| ;; | |
| esac | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment