Skip to content

Instantly share code, notes, and snippets.

@augustohp
Last active August 29, 2015 14:00
Show Gist options
  • Save augustohp/11193673 to your computer and use it in GitHub Desktop.
Save augustohp/11193673 to your computer and use it in GitHub Desktop.
Jekyll init script for debian (serves Ubuntu).
#!/bin/bash
#
# Jekyll is a Ruby based website/blog generator, this is his
# (unnoficial) init script. Tested with Jekyll 1.5.
# Author: Augusto Pascutti <augusto.hp@gmail.com>
set -o errexit
set -o pipefail
[[ $DEBUG ]] && set -x
declare -r SOURCE=/var/www
declare -r PID_FILE=/var/run/jekyll.pid
declare -r LOG_FILE=/var/log/jekyll.log
declare -r JEKYLL="$(which jekyll)"
declare -r JEKYLL_CONFIG="$SOURCE/_config.yml"
declare -r JEKYLL_OPTIONS="--trace serve --watch --config $JEKYLL_CONFIG"
[[ "$JEKYLL" == "" ]] && (echo "Jekyll not installed. Try 'gem install jekyll'."; exit 2);
[[ ! -f "$JEKYLL_CONFIG" ]] && (echo "Jekyll configuration ($JEKYLL_CONFIG) not found."; exit 2);
[[ "$(id -u)" -ne 0 ]] && (echo "Jekyll init script needs to be executed by root."; exit 2);
function jekyll_is_running()
{
[[ -f "$PID_FILE" ]] || return 1;
JEKYLL_PID="$(cat $PID_FILE)"
[[ -z "$JEKYLL_PID" ]] && return 1;
[[ -z "$(ps --no-heading -p $JEKYLL_PID)" ]] && return 1 || return 0;
}
case "$1" in
start)
$JEKYLL $JEKYLL_OPTIONS >> $LOG_FILE 2>&1 &
echo $! > $PID_FILE
echo "Jekyll watcher started."
exit 0
;;
stop)
jekyll_is_running || (echo 'Jekyll is not running.'; exit 1;)
kill -TERM $(cat $PID_FILE) && rm -f $PID_FILE && echo "Jekyll watcher stopped."
exit 0
;;
restart)
$0 stop && $0 start && exit 0
;;
status)
echo -n "Jekyll is "
jekyll_is_running && echo 'running' || echo 'not running.'
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
# vim : set syntax=sh sw=4 ts=4:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment