LoginSignup
21
21

More than 5 years have passed since last update.

RaspberryPi上でhubotが自動起動するように設定する

Last updated at Posted at 2015-01-25

環境

Raspbian: ver December 2014
node.js: 0.10.35

手順

1.nodeをデーモン化

nodeをdaemonとして動かすためのモジュールforeverをインストール。

$ npm install -g forever

hubotを動かすために叩いているbin/hubotを以下の用に書き換える(execの行をコメントアウト、foreverの行を追加)。Slackなどのサービスと連携させる人はここで環境変数の設定もしたほうがいいかも。

#!/bin/sh

set -e

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

forever start -c coffee node_modules/.bin/hubot -a slack
# exec node_modules/.bin/hubot "$@"

ここまで上手く出来ていればhubot起動時にバックグラウンドで動くはず。

$ bin/hubot
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: node_modules/.bin/hubot

2.起動時に実行

init.dディレクトリにhubotファイルを追加。bin/hubotを実行するようなスクリプトを書く。

/etc/init.d/hubot
#!/bin/sh
DIR="hubotのディレクトリパスを書く"
cd $DIR
sudo -u pi ./bin/hubot

実行権限を追加。これをやらない場合を試してないけどたぶん必要だよね..?

$ sudo chmod +x /etc/init.d/hubot

init.d以下に置くだけでは実行されないので以下のコマンドを実行。

$ sudo update-rc.d hubot defaults 99 1

うまくできていると、reboot後にサービスが自動起動しているはず。

$ sudo reboot

$ forever list
info:    Forever processes running
data:        uid  command script                           forever pid  id logfile                    uptime       
data:    [0] zytY coffee  node_modules/.bin/hubot -a slack 2301    2318    /home/pi/.forever/zytY.log 0:0:0:55.887 
21
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
21