hubot install on CentOS7

(1)Node.js install
#sudo yum install epel-release
#sudo yum install nodejs npm

#sudo npm install -g jsfmt
#sudo npm install -g sails
#sudo npm install -g node-dev
#sudo npm install -g pm2

(2)npm install
#yum install gcc gcc-c++
#git clone https://github.com/isaacs/npm.git
#cd npm/
#make
#make install
#npm

(3)hubot install
# epelリポジトリを追加
$yum -y install epel-release
$vi /etc/yum.repos.d/epel.repo
[epel]部分の「enabled=1」を「enabled=0」に変更して、標準では見に行かないようにする

# redisを追加
hubotはredisとnpmを使うので両方ともインストール
$ sudo yum install epel-release
$ wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
$ sudo rpm -Uvh remi-release-7*.rpm

$ sudo yum --enablerepo=remi,remi-test,epel install redis

# redis起動
$ systemctl start redis

# redis 自動起動設定
$systemctl enable redis
npmアップデート
手順としては不要かもしれないが、念のためアップデート

#npm update -g npm

# hubotに必要なnpmモジュールをインストール
$npm install -g coffee-script hubot
$npm install -g yo generator-hubot
$npm install hubot-slack --save

(4)slack設定
# slackのアカウントとチームを作成する
この作業はブラウザから作業します。
今回はhubotをslackbotとして使いますので、slackのアカウントとチームを用意します。

(5)hubot設定
# 作成したチームにhubotを登録する
hubotはこちらより登録可能
https://gcecontrol.slack.com/apps/A0F7XDU93-hubot

画面に従って作成し、チームに登録します。途中TOKENが表示されるので控える

例)HUBOT_SLACK_TOKEN=xoxb-XXXX-XXXX

発言させたいチャネルにhubotを登録しておきます。

# サーバにhubotを作成する
この作業はサーバ側で行います。
まずサーバ側にhubotをセットアップします。

$mkdir hubot && cd hubot
$yo hubot

$ mkdir matter-bot && cd matter-bot
$ yo hubot --adapter mattermost --owner=user@example.com --name=matter-bot --description=sample


#起動スクリプトを書く
$vi run.sh
-------
#!/bin/bash
export HUBOT_SLACK_TOKEN=xoxb-XXXX-XXXX
 export HUBOT_SLACK_EXIT_ON_DISCONNECT=true
 cd `dirname $0`
node_modules/.bin/hubot --adapter slack
----------------

# 応答用のcoffeeスクリプトを書く
vi example.coffee
----------
module.exports = (robot) ->
 robot.hear /hello/, (msg) ->
 msg.send msg.random [
 'hello',
 'what?'
 ]
ーーーーーーーーーーーーーー


$sh run.sh

# slackより動作確認
helloを打つと、what?と返してくれます。

# foreverをinstall
$npm install forever -g

# systemd用の起動コマンドを作成する
vi /etc/systemd/system/forever-hubot.service
-------------
[Unit]
 Description=run forever hubot
 After=network.target
[Service]
 Type=simple
 RemainAfterExit=yes
 ExecStart=/home/app/hubot/run.sh
 User=app
[Install]
 WantedBy=multi-user.target
 $systemctrl forever-hubot start
 $systemctl enable forever-hubot
-------------- 

デーモンリロード
$systemctl daemon-reload

開始
$systemctl start forever-hubot

自動起動設定
$systemctl enable forever-hubot

これでhubotが自動起動となる

coffeescript 1.10.0



コメント

人気の投稿