-
-
Save tigefa4u/91805bc5707c94b848c0 to your computer and use it in GitHub Desktop.
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/bash | |
# REDMINE | |
# Maintainer: @thanhhh | |
# App Version: 2.3.1 | |
APP_ROOT="/var/www/redmine" | |
APP_USER="www-data" | |
DAEMON_OPTS="$APP_ROOT/script/rails" | |
# rvm use 2.0.0 --default | |
RVM_DEFAULT="/usr/local/rvm/rubies/default/bin/ruby" | |
PID_PATH="$APP_ROOT/tmp/pids" | |
WEB_SERVER_PID="$PID_PATH/redmine.pid" | |
NAME="redmine" | |
DESC="Redmine service" | |
check_pid(){ | |
if [ -f $WEB_SERVER_PID ]; then | |
PID=`cat $WEB_SERVER_PID` | |
STATUS=`ps aux | grep $PID | grep -v grep | wc -l` | |
else | |
STATUS=0 | |
PID=0 | |
fi | |
} | |
execute() { | |
sudo -u $APP_USER -H bash -l -c "$1" | |
} | |
start() { | |
cd $APP_ROOT | |
check_pid | |
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then | |
# Program is running, exit with error code 1. | |
echo "Error! $DESC $NAME is currently running!" | |
exit 1 | |
else | |
if [ `whoami` = root ]; then | |
execute "$RVM_DEFAULT $DAEMON_OPTS server webrick -p 3434 -e production" | |
echo "$DESC started" | |
fi | |
fi | |
} | |
stop() { | |
cd $APP_ROOT | |
check_pid | |
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then | |
## Program is running, stop it. | |
kill -QUIT `cat $WEB_SERVER_PID` | |
rm "$WEB_SERVER_PID" >> /dev/null | |
echo "$DESC stopped" | |
else | |
## Program is not running, exit with error. | |
echo "Error! $DESC not started!" | |
exit 1 | |
fi | |
} | |
restart() { | |
cd $APP_ROOT | |
check_pid | |
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then | |
echo "Restarting $DESC..." | |
kill -USR2 `cat $WEB_SERVER_PID` | |
echo "$DESC restarted." | |
else | |
echo "Error, $NAME not running!" | |
exit 1 | |
fi | |
} | |
status() { | |
cd $APP_ROOT | |
check_pid | |
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then | |
echo "$DESC / Puma with PID $PID is running." | |
else | |
echo "$DESC is not running." | |
exit 1 | |
fi | |
} | |
## Check to see if we are running as root first. | |
## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html | |
if [ "$(id -u)" != "0" ]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
restart | |
;; | |
reload|force-reload) | |
echo -n "Reloading $NAME configuration: " | |
kill -HUP `cat $PID` | |
echo "done." | |
;; | |
status) | |
status | |
;; | |
*) | |
echo "Usage: sudo service redmine {start|stop|restart|reload}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment