Created
September 23, 2009 14:52
-
-
Save cypher/192051 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
### BEGIN INIT INFO | |
# Provides: god control | |
# Required-Start: $remote_fs $syslog | |
# Required-Stop: $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Starts god at boot time | |
# Description: Starts god and all the services it is supposed to watch | |
### END INIT INFO | |
# | |
# god startup | |
# cypher, Fri May 8 11:54:53 CEST 2009 | |
# based on nostromos iptables script | |
# | |
# | |
# update-rc.d god.sh start 40 S . stop 89 0 6 . | |
# | |
# config: God config file | |
GOD_CONFIG= | |
# config: Log level. Must be one of [debug|info|warn|error|fatal] | |
GOD_LOG_LEVEL=warn | |
# config: Disables output to syslog if set to true | |
GOD_NO_SYSLOG=true | |
# config: Location of the log file. Leave empty for default location | |
GOD_LOG_FILE=/root/god.log | |
# config: God files to load on startup | |
GOD_STARTUP_FILES=(/home/assets/assets/god/asset.god) | |
# | |
# do not modify beyond this line, except you really know what | |
# you're doing... you've been warned! | |
# | |
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin | |
GOD=$(which god) | |
if ! [ -x $GOD ]; then | |
echo "There is no god (god binary not found/set). exiting.." | |
exit 0 | |
fi | |
god_start () { | |
GOD_OPTIONS='' | |
# Pass config file to god if $GOD_CONFIG is set (and readable) | |
if [[ -n "${GOD_CONFIG}" ]]; then | |
if [[ -r $GOD_CONFIG ]]; then | |
GOD_OPTIONS="-c ${GOD_CONFIG}" | |
else | |
echo "Warning: god config file '$GOD_CONFIG' doesn't exist and/or isn't readable. Skipping.." | |
fi | |
fi | |
# Set the log level | |
if [[ -n "${GOD_LOG_LEVEL}" ]] && [[ "${GOD_LOG_LEVEL}" =~ /^debug|info|warn|error|fatal$/ ]]; then | |
GOD_OPTIONS="${GOD_OPTIONS} --log-level ${GOD_LOG_LEVEL}" | |
else | |
echo 'Warning: You need to set GOD_LOG_LEVEL to one of [debug|info|warn|error|fatal]!' | |
echo "Defaulting log level to 'warn'." | |
GOD_OPTIONS="${GOD_OPTIONS} --log-level warn" | |
fi | |
# Disable syslog | |
if [[ -n "${GOD_NO_SYSLOG}" ]]; then | |
GOD_OPTIONS="${GOD_OPTIONS} --no-syslog" | |
fi | |
# Set path to logfile | |
if [[ -n "${GOD_LOG_FILE}" ]]; then | |
GOD_OPTIONS="${GOD_OPTIONS} --log ${GOD_LOG_FILE}" | |
fi | |
$GOD $GOD_OPTIONS | |
for file in ${GOD_STARTUP_FILES[*]} | |
do | |
# Make sure file exists and is readable before loading it | |
if [[ -r $file ]]; then | |
$GOD load $file | |
else | |
echo "Warning: File '$file' doesn't exist and/or isn't readable. Skipping.." | |
fi | |
done | |
} | |
god_stop () { | |
$GOD terminate | |
} | |
god_restart () { | |
god_stop | |
god_start | |
} | |
god_status() { | |
echo "running god check.." | |
$GOD check | |
echo "status:" | |
$GOD status | |
} | |
case "$1" in | |
start) | |
echo -n "starting god.. " | |
god_start | |
echo "done." | |
;; | |
restart) | |
echo -n "restarting god.. " | |
god_restart | |
echo "done." | |
;; | |
stop) | |
echo -n "stopping god.. " | |
god_stop | |
echo "done." | |
;; | |
status) | |
god_status | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart|status}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment