Skip to content

Instantly share code, notes, and snippets.

@ddavison
Created February 22, 2016 00:38
Show Gist options
  • Save ddavison/fdb481725598927cdff3 to your computer and use it in GitHub Desktop.
Save ddavison/fdb481725598927cdff3 to your computer and use it in GitHub Desktop.
Run a Jekyll site as an Ubuntu Service
#!/bin/sh -e
# ========================
# Start a Jekyll Server
# ========================
#
# Usage: /etc/init.d/jekyll-site {start|stop|force-reload|restart|status}
#
### BEGIN INIT INFO
# Provides: jekyll-site
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start jekyll-site jekyll server
### END INIT INFO
DEFAULT_PID_FILE="/var/run/jekyll-site.pid"
DEFAULT_LOG_FILE="/var/log/jekyll-site.log"
NAME=jekyll-site
DESC=jekyll-site
DAEMON=/etc/init.d/jekyll-site
SITEDIR="/srv/jekyll-site"
JEKYLL=$(which jekyll)
if [ -z "$PID" ]
then
PID=$DEFAULT_PID_FILE
fi
do_start() {
start-stop-daemon \
--make-pid \
--quiet \
--background \
--start \
--pidfile $DEFAULT_PID_FILE \
--chdir $SITEDIR \
--chuid $USER:$USER \
--exec $JEKYLL serve -- build \
--port 8080 \
--watch >> $DEFAULT_LOG_FILE 2>&1
}
do_stop() {
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PID
RETVAL="$?"
sleep 1
return "$RETVAL"
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
restart)
do_stop
do_start
;;
status)
status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $?
;;
*)
echo "Usage: $NAME {start|stop|restart|status}" >&2
exit 3
;;
esac
@inetbiz
Copy link

inetbiz commented Jan 29, 2017

I could not get this script to work on ubuntu 16.10 @ddavison

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