hubot-example
hubot-example copied to clipboard
CentOS init script doesn't stop node process
Starting Hubot with the CentOS init script spawns a runuser command, which in turn invokes a node process to run the actual bot. Executing /etc/init.d/hubot stop properly terminates the runuser process, but does not terminate the node process.
@skpy thanks for noticing. I've found that it works well if you're running /etc/init.d/hubot start from hubot user rather than from root. Starting with another user saves pid of runuser process as hubot.pid, and killing runuser doesn't stop the node process since it doesn't care about it's parent. Try starting / stopping / restarting hubot with su - hubot -c "/etc/init.d/hubot start | stop | restart". Use it as a workaround, and I'll think how to improve the script so it works as expected from any user.
Also, I use this script for restarting from chat with hubot restart command. It runs from hubot user and works as expected:
child_process = require 'child_process'
module.exports = (robot) ->
robot.respond /restart( yourself)?$/i, (msg) ->
msg.send "Restarting, please wait... (elevator music)"
robot.brain.save()
# Give hubot a second to dump it's brain
setTimeout( ->
try
child_process.exec '/etc/init.d/hubot restart', (error, stdout, stderr) ->
catch error
msg.send "'/etc/init.d/hubot restart' failed: " + error
, 1000)
I found that this init script worked successfully: https://raw.githubusercontent.com/visibilityspots/scripts/master/hubot
re: https://raw.githubusercontent.com/visibilityspots/scripts/master/hubot
the part that makes this work seems risky, though: PID=$(ps aux | grep node | head -1 | awk '{print $2}') This won't work reliably if there are other process with 'node' in the name. "pgrep -u hubot ${USER}" might work a little more safely
I've had good luck with 'daemonize' in the past, however, it will sanitize the environment, which might make pulling in environment variables difficult.
With the other script, I tried assigning $PARENT_PID from $! of 'runuser' and then doing a pgrep -P, but looks like runuser makes a bash call, which in turn runs 'node', so this approach doesn't work either.