Instantly share code, notes, and snippets.

@kkurahar /bot
Last active May 24, 2016

Embed
What would you like to do?
Hubotの自動更新用スクリプト。 foreverの自動起動機能を利用して利用する想定。 $ /path/to/hubot/bin/bot start
#!/bin/sh
export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"
##export HUBOT_LOG_LEVEL="debug"
## HipChat
export HUBOT_HIPCHAT_TOKEN=""
export HUBOT_HIPCHAT_JID=""
export HUBOT_HIPCHAT_PASSWORD=""
##export HUBOT_HIPCHAT_ROOMS=""
case $1 in
"start")
sudo npm uninstall hubot-hipchat
sudo npm install hubot-hipchat
sudo npm install
./node_modules/forever/bin/forever $1 \
-c coffee node_modules/hubot/bin/hubot -a hipchat
;;
"stop")
./node_modules/forever/bin/forever $1 \
-c coffee node_modules/hubot/bin/hubot -a hipchat
* ) echo "usage: bot start|stop" ;;
esac
# Description
# Allows hubot to update itself using git pull and restart process
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot update - Performs a git pull and npm udate.
#
# Author:
#
child_process = require 'child_process'
module.exports = (robot) ->
robot.respond /update( yourself)?$/i, (msg) ->
try
msg.send "git pull..."
child_process.exec 'git pull', (error, stdout, stderr) ->
if error
msg.send "git pull failed: " + stderr
else
output = stdout+''
if not /Already up\-to\-date/.test output
msg.send "Hubot changed:\n" + output + "\nBegin restart..."
## TODO
process.exit()
else
msg.send "Hubot is up-to-date"
catch error
msg.send "git pull failed: " + error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment