strongloop / strong-pm

deployer for node applications
http://strong-pm.io
Other
1k stars 71 forks source link

How can I start Hubot using strong-pm? #246

Closed bossyang closed 9 years ago

bossyang commented 9 years ago

Every hubot install has a bin/hubot script to handle starting up the hubot. Currently I use PM2 to manage the server process. Is there anyway porting this to strong-pm?

sam-github commented 9 years ago

strong-pm will run the first found of these: https://github.com/strongloop/strong-supervisor/blob/master/bin/sl-run.txt#L5-L11

Creating a server.js in the root of your package that looked like:

require('./bin/hubot')

would probably work. Test it by running your hubot with slc run . in the root of your package, and see if it runs. If it does, pm can use run it.

bossyang commented 9 years ago

No, it doesn't work.

INFO strong-agent v1.6.0 profiling app 'another-bot' pid '21464'
INFO strong-agent[21464] started profiling agent
INFO supervisor reporting metrics to `internal:`
supervisor running without clustering (unsupervised)

/home/bossyang/workspace/another_bot/bin/hubot:5
npm install
    ^^^^^^^
SyntaxError: Unexpected identifier
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at Module.module.__proto__.require (/usr/lib/node_modules/strongloop/node_modules/strong-agent/lib/agent.js:247:42)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/bossyang/workspace/another_bot/server.js:1:63)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
sam-github commented 9 years ago
/home/bossyang/workspace/another_bot/bin/hubot:5
npm install

Have you looked at bin/hubot? Its not javascript, its some kind of shell script, that apparently runs npm install, and then, I assume, runs the actual application main. Shell scripts can't be required by node.

What, exactly, is the main _node javascript_ file for your bot?

bossyang commented 9 years ago

Yes, bin/hubot is a shell script. It runs another shell script via node. The file is generated by hubot yeoman generator. I just put my bot scripts under scripts folder. With PM2, I need set interpreter to bash.

bin/hubot

#!/bin/sh

set -e

npm install
export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"

exec node_modules/.bin/hubot --name "jbot" "$@"

node_modules/hubot/bin/hubot

#!/usr/bin/env coffee
# vim:ft=coffee ts=2 sw=2 et :
# -*- mode:coffee -*-

Hubot    = require '..'

Fs       = require 'fs'
OptParse = require 'optparse'
Path     = require 'path'
sam-github commented 9 years ago

strong-pm injects instrumentation into node before passing control to your javascript: it must run javascript, not bash.

If you have a js file you can run as your main, you can use strong-pm, but if your node app only runs with a shell script wrapper, I don't thin pm will work for you.

bossyang commented 9 years ago

@sam-github Thanks.