pm2+hubot

スポンサーリンク

hubotをpm2で動かすのに四苦八苦したメモ。
hubot adapterはxmppを使用。
pm2起動時にbind addressを指定する方法が良くわからず 0.0.0.0 でbindされている。
export BIND_ADDRESS=127.0.0.1で指定可能

process.jsonを作って pm2 start process.json で起動する

process.json

{
    "apps":[
        {
            "name"                  : "psyclonebot",
            "cwd"                   : "/var/www/hubot.psycl.one",
            "script"                : "node_modules/.bin/coffee",
            "exec_interpreter"      : "coffee",
            "args"                  : "-- node_modules/.bin/hubot --adapter xmpp --name psyclonebot",
            "node_args"             : ["--no-deprecation"],
            "log_date_format"       : "YYYY-MM-DDTHH:mm:ssZ",
            "error_file"            : "/var/www/hubot.psycl.one/.pm2/logs/hubot.err.log",
            "out_file"              : "/var/www/hubot.psycl.one/.pm2/logs/hubot.log",
            "pid_file"              : "/var/www/hubot.psycl.one/.pm2/logs/hubot.pid",
            "exec_mode"             : "cluster",
            "instances"             : 1,
            "min_uptime"            : "200s",
            "max_restarts"          : 0,
            "max_memory_restart"    : "150M",
            "watch"                 : true,
            "ignore_watch"          : ["[\\/\\\\]\\./", "node_modules"],
            "merge_logs"            : true,
            "autorestart"           : true,
            "vizion"                : false,
            "env": {
                "NODE_ENV"               : "production",
                "HUBOT_SLACK_BOTNAME"    : "***",
                "HUBOT_SLACK_TEAM"       : "***",
                "HUBOT_XMPP_HOST"        : "***.xmpp.slack.com",
                "HUBOT_XMPP_USERNAME"    : "***@***.xmpp.slack.com",
                "HUBOT_XMPP_PASSWORD"    : "***.***",
                "HUBOT_XMPP_ROOMS"       : "general@***.***.xmpp.slack.com",
                "REDIS_URL"              : "redis://127.0.0.1:6379",
                "PORT"                   : "9999",
                "HUBOT_LOG_LEVEL"        : "INFO",
                "BIND_ADDRESS"           : "127.0.0.1"
            }
        }
    ]
}

起動

pm2 start process.json
[PM2] Stopping PM2...
[PM2] deleteProcessId process id 0
[PM2] All processes have been stopped and deleted
[PM2] PM2 stopped
[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
[PM2] Process launched
┌─────────────┬────┬─────────┬───────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name    │ id │ mode    │ pid   │ status │ restart │ uptime │ memory      │ watching │
├─────────────┼────┼─────────┼───────┼────────┼─────────┼────────┼─────────────┼──────────┤
│ psyclonebot │ 0  │ cluster │ 16184 │ online │ 0       │ 0s     │ 17.070 MB   │  enabled │
└─────────────┴────┴─────────┴───────┴────────┴─────────┴────────┴─────────────┴──────────┘

確認

sudo netstat -lnatp | grep PM2
tcp        0      0 0.0.0.0:9999            0.0.0.0:*               LISTEN      16256/PM2 v0.14.5:
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      5276/PM2 v0.14.5: G

[amazonjs asin=”B00URMH4UK” locale=”JP” title=”Automation and Monitoring with Hubot: For DevOps and Developers (English Edition)”]

コメント

タイトルとURLをコピーしました