Skip to content

Instantly share code, notes, and snippets.

@yongjhih
Last active August 29, 2015 14:02
Show Gist options
  • Save yongjhih/d4852610902177e5a82d to your computer and use it in GitHub Desktop.
Save yongjhih/d4852610902177e5a82d to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Startup / shutdown script for the couchbase sync_gateway
#
if [ "$(id -u)" != "0" ]; then
echo "Must run as root"
exit 1
fi
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON_PATH=/opt/couchbase-sync-gateway/bin/
DAEMON="${DAEMON_PATH}sync_gateway"
#DAEMON="/home/andrew/workspace/sync-gateway/sync-gateway"
DAEMONOPTS=/opt/couchbase-sync-gateway/etc/sync-gateway.json
LOGFILE=/opt/couchbase-sync-gateway/var/lib/couchbase/logs/start.log
PIDFILE=/opt/couchbase-sync-gateway/var/lib/couchbase/couchbase-sync-gateway.pid
NAME=couchbase-sync-gateway
USER=couchbase-sync-gateway
DESC="Couchbase sync_gateway"
# /etc/security/limits.d/couchbase.conf
# couchbase-sync-gateway soft nofile 32769
# couchbase-sync-gateway hard nofile 32769
# couchbase-sync-gateway soft memlock 1048576
# couchbase-sync-gateway hard memlock 2097152
ulimit -Sn 32768
ulimit -Hn 32768
ulimit -Sm 2097152
ulimit -Hm 2097152
case "$1" in
start)
printf "%-50s" "Starting $NAME..."
cd $DAEMON_PATH
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --chuid $USER --exec $DAEMON -- $DAEMONOPTS > $LOGFILE 2>&1 &
echo
;;
status)
printf "%-50s" "Checking $NAME..."
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
printf "%s\n" "Process dead but pidfile exists"
else
echo "Running"
fi
else
printf "%s\n" "Service not running"
fi
;;
stop)
printf "%-50s" "Stopping $NAME"
PID=`cat $PIDFILE`
cd $DAEMON_PATH
if [ -f $PIDFILE ]; then
kill -HUP $PID
printf "%s\n" "Ok"
rm -f $PIDFILE
else
printf "%s\n" "pidfile not found"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {status|start|stop|restart}"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment