Created
May 7, 2014 12:20
-
-
Save guedressel/9300f94eca9d4eca9a5f to your computer and use it in GitHub Desktop.
Init-script to run graphite-web as FastCGI Daemon (based on ubuntu package graphite-web 0.9.12+debian-3) + lighttpd example config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: FastCGI server for graphite | |
# Required-Start: networking | |
# Required-Stop: networking | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: S 0 1 6 | |
# Short-Description: Start/Stop FastCGI server of graphite-web package. | |
# Description: Grahpite-web is a Django webapp. Django has a built-in FastCGI server | |
# which is started/stopped by this init script. | |
### END INIT INFO | |
# | |
# Author: Günter Dressel <g.dressel@cyledge.com> | |
# Inspired by Script of Guillermo Fernandez Castellanos available at https://gist.github.com/fwenzel/285758#file_django_servers.sh | |
DESC="Graphite FastCGI daemon" | |
NAME=graphite-fcgi | |
DAEMON="/usr/bin/graphite-manage" | |
RUN_AS_USER="_graphite" | |
RUN_AS_GROUP="_graphite" | |
RUN_DATA_DIR="/var/run/graphite-fcgi" | |
PIDFILE="$RUN_DATA_DIR/pid" | |
SOCKET="$RUN_DATA_DIR/socket" | |
DAEMON_ARGS="runfcgi method=threaded socket=$SOCKET pidfile=$PIDFILE daemonize=true" | |
SCRIPTNAME=/etc/init.d/$NAME | |
[ -x "$DAEMON" ] || exit 0 | |
. /lib/lsb/init-functions | |
# | |
# Function that starts the daemon/service. | |
# | |
do_start() | |
{ | |
if [ ! -d $RUN_DATA_DIR ] | |
then | |
mkdir -p $RUN_DATA_DIR | |
chown $RUN_AS_USER:$RUN_AS_GROUP $RUN_DATA_DIR | |
chmod 0775 $RUN_DATA_DIR | |
fi | |
# Starting the Django FastCGI process | |
if [ -f $PIDFILE ]; then | |
echo -n " already running" | |
else | |
start-stop-daemon --start --chuid $RUN_AS_USER:$RUN_AS_GROUP --pidfile $PIDFILE --exec $DAEMON $DAEMON_ARGS || return 2 | |
RETVAL="$?" | |
[ $RETVAL = "0" ] && chmod 0777 $SOCKET | |
fi | |
return $RETVAL | |
} | |
# | |
# Function that stops the daemon/service. | |
# | |
do_stop() { | |
# Killing the Django FastCGI process | |
start-stop-daemon --stop --quiet --pidfile $PIDFILE || return 2 | |
RETVAL="$?" | |
if [ -f $PIDFILE ]; then | |
rm $PIDFILE | |
fi | |
return $RETVAL | |
} | |
case "$1" in | |
start) | |
log_daemon_msg "Starting $DESC" "$NAME" | |
do_start | |
case "$?" in | |
0) log_end_msg 0 ;; | |
*) log_end_msg 1 ;; | |
esac | |
;; | |
stop) | |
log_daemon_msg "Sopping $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0) log_end_msg 0 ;; | |
*) log_end_msg 1 ;; | |
esac | |
;; | |
status) | |
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? | |
;; | |
restart) | |
log_daemon_msg "Restarting $DESC" "$NAME" | |
do_stop | |
sleep 1 | |
do_start | |
case "$?" in | |
0) log_end_msg 0 ;; | |
*) log_end_msg 1 ;; | |
esac | |
;; | |
*) | |
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2 | |
exit 3 | |
;; | |
esac | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# lighttpd.conf file to act as http-server for the graphite-fcgi daemon | |
# | |
server.modules = ( | |
"mod_access", | |
"mod_alias", | |
"mod_compress", | |
"mod_redirect", | |
"mod_rewrite", | |
"mod_fastcgi" | |
) | |
server.document-root = "/var/www" | |
server.upload-dirs = ( "/var/cache/lighttpd/uploads" ) | |
server.errorlog = "/var/log/lighttpd/error.log" | |
server.pid-file = "/var/run/lighttpd.pid" | |
server.username = "www-data" | |
server.groupname = "www-data" | |
server.port = 80 | |
index-file.names = ( "index.html" ) | |
static-file.exclude-extensions = ( ".fcgi" ) | |
compress.cache-dir = "/var/cache/lighttpd/compress/" | |
compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" ) | |
# Ubuntu package default include: | |
include_shell "/usr/share/lighttpd/create-mime.assign.pl" | |
fastcgi.server = ( | |
"/graphite.fcgi" => ( | |
"graphite" => ( | |
"socket" => "/var/run/graphite-fcgi/socket", | |
"check-local" => "disable", | |
) | |
), | |
) | |
alias.url = ( | |
"/static" => "/usr/share/graphite-web/static/", | |
) | |
url.rewrite-once = ( | |
"^(/static.*)$" => "$1", | |
"^/favicon\.ico$" => "/media/favicon.ico", | |
"^(/.*)$" => "/graphite.fcgi$1", | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment