Created
January 14, 2013 01:58
-
-
Save lottspot/4527265 to your computer and use it in GitHub Desktop.
Init script for the gollum wiki engine
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 | |
GOLLUM_DIR='/home/git/docs.git' | |
GOLLUM_USER='gollum-data' | |
CURRENT_USER=$(whoami) | |
INVOCATION='gollum --mathjax --user-icons gravatar' | |
PID=${$} | |
as_user(){ | |
21[[ ${GOLLUM_USER} != ${CURRENT_USER} ]] && su ${GOLLUM_USER} -c "$1" | |
[[ ${GOLLUM_USER} == ${CURRENT_USER} ]] && bash -c "$1" | |
} | |
[[ ${GOLLUM_USER} != ${CURRENT_USER} && $(id -u) -gt 0 ]] && echo "Please run script as root or gollum user" && exit 1 | |
[[ ${#*} -gt 1 || ${#*} -lt 0 ]] && echo "usage: ${0} [start|stop|status]" && exit 0 | |
case $1 in | |
start) | |
[[ $(ps -e | egrep -v "${$}" | egrep "\bgollum$") ]] && echo "gollum is already running." && exit 0 | |
cd ${GOLLUM_DIR} | |
as_user "nohup ${INVOCATION} >>~/gollum.log 2>&1 &" | |
[[ ! $(ps -e | egrep -v "${$}" | egrep "\bgollum$") ]] && echo "gollum did not start." && exit 1 | |
echo "gollum started successfully." | |
;; | |
stop) | |
[[ ! $(ps -e | egrep -v "${$}" | egrep "\bgollum$") ]] && echo "gollum is already stopped." && exit 0 | |
killall gollum | |
sleep 1 | |
[[ ! $(ps -e | egrep -v "${$}" | egrep "\bgollum$") ]] && echo "gollum has stopped." && exit 0 | |
echo "Stopping gollum..." | |
sleep 3 | |
if [[ $(ps -e | egrep -v "${$}" | egrep "\bgollum$") ]] | |
then | |
echo "gollum has not stopped yet... waiting longer" && sleep 5 | |
[[ ! $(ps -e | egrep -v "${$}" | egrep "\bgollum$") ]] && echo "gollum has stopped." && exit 0 | |
echo "gollum did not stop." && exit 1 | |
else | |
echo "gollum stopped successfully."; exit 0 | |
fi | |
;; | |
status) | |
if [[ $(ps -e | egrep -v "${$}" | egrep "\bgollum$") ]] | |
then | |
echo "gollum is running" | |
else | |
echo "gollum is not running" | |
fi | |
;; | |
debug) | |
result=$(ps -e | egrep -v "${$}" | egrep "\bgollum$") | |
echo $result | |
;; | |
*) | |
echo "usage: ${0} [start|stop|status]" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment