Skip to content

Instantly share code, notes, and snippets.

@centminmod
Forked from brantfaircloth/ghost.sh
Created November 26, 2013 09:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save centminmod/7655951 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# ghost - this script starts the ghost blogging package
#
# chkconfig: - 95 20
# description: ghost is a blogging platform built using javascript \
# and running on nodejs
#
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
home="/home/ghost/ghost-0.3.3/"
exec="/usr/bin/node index.js >> /home/ghost/ghost.log &"
prog="ghost"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
lockfile=/var/lock/subsys/$prog
start() {
#[ -x $exec ] || exit 5
echo -n $"Starting $prog: "
# if not running, start it up here, usually something like "daemon $exec"
export NODE_ENV=production
cd $home
daemon --user=ghost $exec
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
# stop it here, often "killproc $prog"
pid=`ps -u $prog -fw | grep $prog | grep -v " grep " | awk '{print $2}'`
kill -9 $pid > /dev/null 2>&1 && echo_success || echo_failure
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
my_status() {
local base pid lock_file=
base=${1##*/}
# get pid
pid=`ps -u $prog -fw | grep $prog | grep -v " grep " | awk '{print $2}'`
if [ -z "${lock_file}" ]; then
lock_file=${base}
fi
# See if we have no PID and /var/lock/subsys/${lock_file} exists
if [[ -z "$pid" && -f /var/lock/subsys/${lock_file} ]]; then
echo $"${base} dead but subsys locked"
return 2
fi
if [ -z "$pid" ]; then
echo $"${base} is stopped"
return 3
fi
if [ -n "$pid" ]; then
echo $"${base} (pid $pid) is running..."
return 0
fi
}
rh_status() {
# run checks to determine if the service is running or use generic status
my_status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 2
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment