Created
February 5, 2016 09:06
-
-
Save emedvedev/3236a3bf104b2f0184f1 to your computer and use it in GitHub Desktop.
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 | |
# | |
# /etc/rc.d/init.d/<servicename> | |
# | |
# Daemon for hubot | |
# | |
# description: Docker container for hubot | |
### BEGIN INIT INFO | |
# Provides: docker-hubot | |
# Required-Start: $network docker | |
# Required-Stop: $network docker | |
# Should-Start: | |
# Should-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: start and stop docker container for hubot | |
# Description: Docker container for hubot | |
### END INIT INFO | |
if [ -e /etc/init.d/functions ]; then | |
. /etc/init.d/functions | |
elif [ -e /lib/lsb/init-functions ]; then | |
. /lib/lsb/init-functions | |
failure() { | |
log_failure_msg "$@" | |
return 1 | |
} | |
success() { | |
log_success_msg "$@" | |
return 0 | |
} | |
else | |
failure() { | |
echo "fail: $@" >&2 | |
exit 1 | |
} | |
success() { | |
echo "success: $@" >&2 | |
exit 0 | |
} | |
fi | |
export HOME=/root/ | |
docker="/usr/bin/docker" | |
prog="docker-hubot" | |
if [ -d /var/lock/subsys ]; then | |
lockfile="/var/lock/subsys/$prog" | |
else | |
unset lockfile | |
fi | |
start() { | |
[ -x $docker ] || exit 5 | |
if [ "true" = "$($docker inspect --format='{{.State.Running}}' hubot)" ]; then | |
failure | |
printf "Container hubot is still running.\n" | |
exit 7 | |
fi | |
printf "Starting $prog:\t" | |
$docker rm stackstorm/hubot >/dev/null 2>&1 | |
$docker run \ | |
--name hubot --net bridge --detach=true \ | |
-m 0b -p 8081:8080 --add-host myhost:10.0.1.100 \ | |
-e ST2_WEBUI_URL=https://myhost \ | |
-e ST2_AUTH_URL=https://myhost:443/auth \ | |
-e ST2_API=https://myhost:443/api \ | |
-e ST2_AUTH_USERNAME=chatops_bot \ | |
-e ST2_AUTH_PASSWORD=x6hgOCD4mWGe9LuOzsXZg0cu4OkCOPNr \ | |
-e EXPRESS_PORT=8081 \ | |
-e NODE_TLS_REJECT_UNAUTHORIZED=0 \ | |
-e HUBOT_ALIAS=! \ | |
-e HUBOT_LOG_LEVEL=debug \ | |
-e HUBOT_NAME=hubot \ | |
-e HUBOT_ADAPTER=yammer \ | |
-e HUBOT_YAMMER_ACCESS_TOKEN=2361395-RlgDFJSgVk3xsLFyOtjPA \ | |
-e HUBOT_YAMMER_GROUPS=Bots \ | |
stackstorm/hubot | |
retval=$? | |
echo | |
if [ $retval -eq 0 ]; then | |
success | |
else | |
failure | |
fi | |
} | |
stop() { | |
echo -n "Stopping $prog: " | |
$docker stop hubot | |
$docker rm hubot | |
return $? | |
} | |
clean() { | |
if ! [ -f $cidfile ]; then | |
failure | |
echo | |
printf "$cidfile does not exist.\n" | |
else | |
cid="$(cat $cidfile)" | |
rm $cidfile | |
$docker rm -f $cid | |
retval=$? | |
return $retval | |
fi | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
if [ "true" = "$($docker inspect --format='{{.State.Running}}' hubot)" ]; then | |
echo $prog is running | |
exit 0 | |
else | |
echo $prog not running | |
exit 1 | |
fi | |
;; | |
restart|reload) | |
stop | |
start | |
;; | |
clean) | |
clean | |
;; | |
cleanRestart) | |
stop | |
clean | |
start | |
;; | |
condrestart) | |
[ -f /var/lock/subsys/$prog ] && restart || : | |
;; | |
*) | |
echo "Usage: $0 [start|stop|status|reload|restart|probe|clean|cleanRestart]" | |
exit 1 | |
;; | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment