AsakusaSatelliteのセットアップ¶
はじめに¶
品川Redmine勉強会 第4回(2012-11-10)の懇親会で、開発チームのコミュニケーションでメーリングリストはなかなか活性化しないという話題から、開発者向けのチャットツールAsakusaSatelliteがいいよと紹介されました。Railsアプリとして作られ、Redmine連携機能があります。
CentOS 6.5上に構築してみる¶
単独(WEBrick)で起動する¶
AsakusaSatelliteのドキュメントのセットアップを見ながらインストールしてみました。
http://docs.asakusa-satellite.org/ja/latest/setup.html
https://github.com/codefirst/AsakusaSatellite/tags
より、AsakusaSatellite-0.9.0.tar.gz をダウンロードし、/opt下に展開
~$ cd /opt opt$ sudo tar xzf /tmp/AsakusaSatellite-0.9.0.tar.gz opt$ sudo ln -s AsakusaSatellite-0.9.0 AsakusaSatellite opt$
Rubyは2.1.1をインストール済みです。
MongoDBをインストールします。
~$ sudo yum install mongodb-server : ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mongodb-server x86_64 2.4.6-1.el6 epel 5.1 M Installing for dependencies: gperftools-libs x86_64 2.0-11.el6.3 epel 246 k libunwind x86_64 1.1-2.el6 epel 54 k snappy x86_64 1.1.0-1.el6 base 39 k v8 x86_64 1:3.14.5.10-7.el6 epel 3.0 M : ~$
MongoDBを自動起動設定し、起動します。
~$ sudo chkconfig mongod on ~$ sudo service mongod start
必要なrubyモジュールをインストールします。
~$ cd /opt/AsakusaSatellite AsakusaSatellite$ sudo bundle install --path .bundle --without development test Your Gemfile lists the gem omniauth-twitter (>= 0.0.14) more than once. You should probably keep only one of them. While it's not a problem now, it could cause errors if you change the version of just one of them later. Fetching gem metadata from https://rubygems.org/....... Fetching additional metadata from https://rubygems.org/.. Using rake (10.1.0) : Installing uglifier (1.2.4) Your bundle is complete! Gems in the groups development and test were not installed. It was installed into ./.bundle Post-install message from httparty: When you HTTParty, you must party hard! Post-install message from rdoc: Depending on your version of ruby, you may need to install ruby rdoc/ri data: <= 1.8.6 : unsupported = 1.8.7 : gem install rdoc-data; rdoc-data --install = 1.9.1 : gem install rdoc-data; rdoc-data --install >= 1.9.2 : nothing to do! Yay! Post-install message from newrelic_rpm: # New Relic Ruby Agent Release Notes # ## v3.6.5 ## * Rails 4.0 Support The Ruby agent is all set for the recent general release of Rails 4.0! We've been tracking the RC's, and that work paid off. Versions 3.6.5 and 3.6.4 of the Ruby agent should work fine with Rails 4.0.0. * Excon and Typhoeus support The Ruby agent now supports the Excon and Typhoeus HTTP libraries! For more details see https://newrelic.com/docs/ruby/ruby-http-clients. See https://github.com/newrelic/rpm/blob/master/CHANGELOG for a full list of changes. AsakusaSatellite$
リソースのコンパイルをします。
AsakusaSatellite$ sudo bundle exec rake assets:precompile RAILS_ENV=production Your Gemfile lists the gem omniauth-twitter (>= 0.0.14) more than once. You should probably keep only one of them. While it's not a problem now, it could cause errors if you change the version of just one of them later. /usr/bin/ruby /usr/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets AsakusaSatellite$
WebSocketサーバーを起動します。
AsakusaSatellite$ sudo bundle exec thin -R socky/config.ru -p3002 -t0 start & :
Webアプリケーションサーバーを起動します。
AsakusaSatellite$ sudo bundle exec rails server -e production : >> Listening on 0.0.0.0:3000, CTRL+C to stop
ブラウザからポート3000にアクセスします。
Apache Passengerで起動する¶
単独起動の確認ができたら、Apache Passengerで起動する設定をします。
config/environments/production.rbを編集
リソースのプリコンパイル
AsakusaSatellite$ sudo bundle exec rake assets:precompile RAILS_ENV=production
Passengerのインストール(gem)
マニュアルでは、gem install でインストールする手順となっていますが、システムグローバルにインストールされそうな気がします。
RedmineのようにAsakusaSatellite/Gemfile.localを作成してbundle updateを試したけどこれは駄目でした。
gem 'passenger'
AsakusaSatellite$ sudo bundle update
直接Gemfileに追加してbundle updateを試します。
gem 'passenger'
AsakusaSatellite$ sudo bundle update
AsakusaSatellite$ sudo bundle exec passenger-install-apache2-module : * Checking for Curl development headers with SSL support... Found: no Error: Cannot find the `curl-config` command. :
エラーになったので、必要そうなcurl developmentを追加
$ sudo yum install libcurl-devel
再度実行
AsakusaSatellite$ sudo bundle exec passenger-install-apache2-module : Please edit your Apache configuration file, and add these lines: LoadModule passenger_module /opt/AsakusaSatellite-0.9.0/.bundle/ruby/2.1.0/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /opt/AsakusaSatellite-0.9.0/.bundle/ruby/2.1.0/gems/passenger-4.0.41 PassengerDefaultRuby /usr/bin/ruby </IfModule> After you restart Apache, you are ready to deploy any number of web applications on Apache, with a minimum amount of configuration! Press ENTER to continue. :
/etc/httpd/conf.d/asakusasatellite.confを作成
LoadModule passenger_module /opt/AsakusaSatellite-0.9.0/.bundle/ruby/2.1.0/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /opt/AsakusaSatellite-0.9.0/.bundle/ruby/2.1.0/gems/passenger-4.0.41 PassengerDefaultRuby /usr/bin/ruby </IfModule> RailsEnv production RailsBaseURI /as
httpのDocumentRootにシンボリックリンクを作成
~$ cd /var/www/html html$ sudo ln -s /opt/AsakusaSatellite/public as
AsakusaSatelliteのインストール以下の所有権をapacheユーザーに変更
AsakusaSatellite$ sudo chown -R apache.apache .
SELinuxを一時的無効化(passengerのためのポリシー定義を頑張ればSELinux下で動きますが・・・)
~$ sudo setenforce 0
~$ sudo service httpd start
Webブラウザで、http://このマシン/as にアクセス
認証方法をRedmine認証にする¶
AsakusaSatelliteの認証はOmniAuthを使用し、デフォルトのプロバイダはTwitterのOAuthを用います。これをRedmineに変更します。Redmine認証プラグイン自体はAsakusaSatelliteの配布パッケージに含まれているので設定を有効化します。
/opt/AsakusaSatellite/config/filter_intra.ymlにあるRedmine認証プラグインのコメントアウトを解除します。
--- filter_intra.yml.1 2014-01-22 19:34:52.000000000 +0900
+++ filter_intra.yml 2014-04-26 18:20:08.305066144 +0900
@@ -20,6 +20,6 @@
- dir: as_desktopnotification
# - dir: as_global_js_css
# - dir: as_watage_plugin
- - dir: as_twitterauth_plugin
+# - dir: as_twitterauth_plugin
# - dir: as_localauth_plugin
-# - dir: as_redmineauth_plugin
+ - dir: as_redmineauth_plugin
/opt/AsakusaSatellite/config/settings.ymlに認証連携するRedmineの情報を記載します。
--- settings.yml.1 2014-01-22 19:34:52.000000000 +0900
+++ settings.yml 2014-04-26 19:14:09.904145487 +0900
@@ -1,13 +1,13 @@
-omniauth:
- provider: "twitter"
- provider_args:
- - "Ug9FZ0r8zp3jwuvOGFYWQ"
- - "qMvcOzyQu4Qkz1bm0k1bOHYDn1m4JF3DXbQK9CWfMA"
-
#omniauth:
-# provider: 'redmine'
+# provider: "twitter"
# provider_args:
-# - 'Redmine URL'
+# - "Ug9FZ0r8zp3jwuvOGFYWQ"
+# - "qMvcOzyQu4Qkz1bm0k1bOHYDn1m4JF3DXbQK9CWfMA"
+
+omniauth:
+ provider: 'redmine'
+ provider_args:
+ - 'http://pecorino/redmine'
#omniauth:
# provider: "local"
httpdを再起動しログインします。ブラウザでサーバーにアクセスし、右上の[Login]をクリックすると、次の3つの入力を要求されます。
Redmine API access keyは、Redmineのユーザー毎に定義される識別文字列で、Redmineにログインして[個人設定]をクリックし、右横のAPIアクセスキーの[表示]をクリックすると表示されます。Profile image URLは空欄でも構いません。
毎回APIキーを入れるのは面倒・・・¶
ログイン時に毎回APIキーを入れるのは面倒です。うーむ・・・
名前の表示が姓名ではなく名姓になる¶
Redmine側では、アカウントの名前は姓と名とをそれぞれ設定します。AsakusaSatelliteでは、Redmineから名前を取り出した後、1つにくっつけて名前として管理します。
- plugins/as_redmineauth_plugin/app/models
21 def screen_name 22 first = @document.root.elements['firstname'].text 23 last = @document.root.elements['lastname'].text 24 "#{first} #{last}" 25 end
ここを順番逆にしてみます。
--- redmine_user.rb.1 2014-01-22 19:34:52.000000000 +0900
+++ redmine_user.rb 2014-04-27 13:46:44.482371945 +0900
@@ -21,7 +21,7 @@
def screen_name
first = @document.root.elements['firstname'].text
last = @document.root.elements['lastname'].text
- "#{first} #{last}"
+ "#{last} #{first}"
end
def exist?
既にRedmine認証でログインしてしまったユーザーはMongoDBにユーザー情報が格納されているので駄目ですが、変更以降にログインしたユーザーについては名前が姓名の順になります。
Redmineチケット連携¶
チャットで#NNと文字列を打つと、Redmineチケットへのリンクにする機能です。
部屋の設定で、Redmine rootとAPI Key、プロジェクト名を記入します。
MonboDB¶
AsakusaSatelliteは、Ruby on RailsのバックエンドのデータベースにMongoDBを使っています。
MongoDBの操作¶
EPELからパッケージmongodbをインストールします。最初EPELからパッケージmongodb-serverをインストールしたのでサーバーは起動しましたが、mongoコマンドがなくあれっとなりました。
コマンドmongoを実行すると、mongodbのインタプリターが起動します。
~$ mongo MongoDB shell version: 2.4.6 connecting to: test Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user >
データベースの一覧を見る
> show dbs asakusa_satellite_production 0.203125GB local 0.078125GB
asakusa_satellite_productionデータベースに入る
> use asakusa_satellite_production switched to db asakusa_satellite_production
コレクション(RDBMSでのテーブルに相当)一覧を見る
> show collections messages rooms system.indexes users
コレクションの中のドキュメント(RDBMSのレコードに相当)を検索する
- SELECT * FROM users; に相当する操作
> db.users.find()
参考¶