Skip to content

Instantly share code, notes, and snippets.

@nl
Created January 21, 2014 15:22
Show Gist options
  • Save nl/8542063 to your computer and use it in GitHub Desktop.
Save nl/8542063 to your computer and use it in GitHub Desktop.
Sync Gateway Upstart Script
description "Sync Gateway Upstart Script”
version "0.1.0"
author "Nicolas Lapomarda"
# Upstart has nothing in $PATH by default
env RUNAS=db
env HOME=/home/$RUNAS
env PATH=$HOME/sync_gateway/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
env PATH_TO_GATEWAY=$HOME/sync_gateway/bin/sync_gateway
env PATH_TO_JSON=$HOME/sync_gateway.json
env LOGSDIR=$HOME/logs
env PIDFILE=/var/run/sync-gateway.pid
# Keep the server running on crash or machine reboot
start on started mountall
stop on shutdown
respawn
pre-start script
mkdir -p $LOGS
chown -R $RUNAS:$RUNAS $LOGS
end script
# Start the Sync Gateway and redirect output streams to log files
script
# Keep a pid around
echo $$ > $PIDFILE
exec su -c “$PATH_TO_GATEWAY $PATH_TO_JSON >> $LOGS/sync_access.log 2>> $LOGS/sync_error.log" $RUNAS
end script
# Remove pid file when we stop the server
pre-stop script
rm $PIDFILE
end script
@nl
Copy link
Author

nl commented Jan 21, 2014

This should be placed in /etc/init/sync-gateway.conf.

You should set:

  • RUNAS to the username the gateway should be run as,
  • PATH_TO_GATEWAY to the path to the gateway binary (output of ./build.sh if you build from source),
  • PATH_TO_JSON to the path of the config JSON file,
  • LOGSDIR to the path of the logs directory.

I also keep a PIDFILE around for monitoring purposes.

@derekdon
Copy link

Thanks for this...

Is env LOGSDIR=$HOME/logs not meant to be env LOGS=$HOME/logs ??

...

Doesn't seem to be working for me...

@sallespromanager
Copy link

can't seem to get it right

start:Unknown job:sync-gateway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment