時間を制したいんじゃ
趣味で作っているアプリとかも時間記録してどのぐらいのスピードで作れるか計りたいなと思い、家に眠っていたらずぱいにRedmineを構築することにした。 趣味で作っているものって1ヶ月以上放置しちゃってまた熱が帯びてやり始めるっていうことが結構多くて、実際何日ぐらいで作ったの?と言われたときに曖昧に答えることが多かった。学生のときは四六時中アプリ作りに時間使えたから1日の平均作業時間×日数で完成までのおおよその時間が出せたけど社会人になってから隙間時間でやることが多く、時間で割り出すことが難しくなった。
(あとRedmineの作業自動化とかまだ知らない機能使うのに実験場がほしかった。会社環境だと失敗許されないし権限等が煩わしいよね。。。)
めちゃくちゃ参考にさせて頂いたサイト
基本的には以下のサイトを参考にしていけばOKでした。ただ環境によって違うのか、詰まった箇所がいくつかあったのでそれだけ書いていきます。
Raspberry PI に Redmine インストール(1) - Wind Messer
Raspberry PI に Redmine インストール(2) - Wind Messer
mysqlで怒られる
sudo RAILS_ENV=production rake db:migrate
のところで以下のエラーが発生
pi@raspberrypi:/usr/share/redmine ▶sudo RAILS_ENV=production rake db:migrate rake aborted! Gem::LoadError: Specified 'mysql' for database adapter, but the gem is not loaded. Add `gem 'mysql'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). Gem::LoadError: mysql is not part of the bundle. Add it to Gemfile. Tasks: TOP => db:migrate => environment (See full trace by running task with --trace)
mysqlがないよというエラーだったのでsudo vim Gemfile
で以下を追加
pi@raspberrypi:/usr/share/redmine ▶sudo vim Gemfile source 'https://rubygems.org' gem "request_store", ">= 1.0.5" gem "mime-types" gem "awesome_nested_set", ">= 3.0.0.rc.6" gem "protected_attributes" gem "actionpack-action_caching" gem "mysql" #←追加 ...
Gemfileに追記したらbundle install
を実行。以下のようにmysqlがインストールされたらOK。
pi@raspberrypi:/usr/share/redmine ▶bundle install Fetching gem metadata from https://rubygems.org/........... Fetching additional metadata from https://rubygems.org/.. Resolving dependencies... Using rake 12.3.1 Using concurrent-ruby 1.0.5 Using i18n 0.9.5 Using json 1.8.6 ... Installing mysql 2.9.1 ...
再度sudo RAILS_ENV=production rake db:migrate
を実行したらDBにテーブルが作られる。
pi@raspberrypi:/usr/share/redmine ▶sudo RAILS_ENV=production rake db:migrate [DEPRECATION] requiring "RMagick" is deprecated. Use "rmagick" instead == 1 Setup: migrating ========================================================= -- create_table("attachments", {:force=>true}) ....
/etc/apache2/sites-available/defaultがない
環境によって違うのかはわからないが、sites-available/default
がない。/etc/apache2/sites-available/000-default.conf
がおそらくsites-available/default
なるものなのでここに以下を追加。
pi@raspberrypi:/usr/share/redmine ▶sudo vim /etc/apache2/sites-available/000-default.conf ... DocumentRoot /var/www/html # ここから <Location "/redmine"> RailsBaseURI /redmine </Location> # ここまで追加 # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, ...
apacheを再起動
sudo /etc/init.d/apache2 restart
「http://らずぱいのIPアドレス/redmine」にアクセスし、以下が表示されればOK。
「個人設定」や「登録する」にアクセスできない
個人設定をクリックすると以下のエラー文が表示される。
Internal error An error occurred on the page you were trying to access. If you continue to experience problems please contact your Redmine administrator for assistance. If you are the Redmine administrator, check your log files for details about the error.
/var/log/apache2/error.log
のログを見ると以下のエラーが出ている。
ActionView::Template::Error (Permission denied @ dir_s_mkdir - /var/cache/redmine/default):
エラー文を見る限り権限問題が発生しているようなので該当の/var/cache/redmine/default
を見に行く。
pi@raspberrypi:/var/cache/redmine ▶cd /var/cache/redmine/default cd: そのようなファイルやディレクトリはありません: /var/cache/redmine/default
Oh...そんなディレクトリがないってよ。 一つ手前に行って確認してみる。
▶cd /var/cache/ pi@raspberrypi:/var/cache ▶ls -l 合計 52K drwxr-xr-x 3 root root 4.0K 4月 10 2017 PackageKit drwxr-xr-x 3 root root 4.0K 8月 31 2017 apache2 drwxr-xr-x 3 root root 4.0K 8月 26 13:38 apt drwxr-xr-x 3 root root 4.0K 8月 26 13:27 dbconfig-common drwxr-xr-x 2 root root 4.0K 8月 26 13:38 debconf drwxr-xr-x 2 root root 4.0K 4月 10 2017 dictionaries-common drwxr-xr-x 2 root root 4.0K 4月 10 2017 fontconfig drwx------ 2 root root 4.0K 8月 26 13:32 ldconfig drwx--x--x 2 root root 4.0K 4月 10 2017 lightdm drwxr-sr-x 36 man root 4.0K 8月 26 13:29 man drwxr-xr-x 2 www-data www-data 4.0K 11月 13 2016 redmine drwxr-xr-x 2 root root 4.0K 4月 1 2017 samba
とりあえずredmineのディレクトリは存在していた。 ただここのredmineディレクトリ以下のファイルは画面アクセスした際に作られるもののはず。もっと根っこのところが怪しいと見た。
解決策
redmine本体の権限がrootだった。
筆者のredmineのインストール先は/usr/share/redmine
。
Redmine本体とは以下のようなファイルが置かれているところ。
pi@raspberrypi:/usr/share/redmine
▶ls
Gemfile app config db lib templates
Gemfile.lock Rakefile bin config.ru extra public test
ここを画面アクセスしたときのユーザー、つまりapache2のユーザーにする。
pi@raspberrypi:/usr/share ▶cd /usr/share ▶sudo chown -R www-data:www-data /usr/share/redmine ⍉ ▶ls -l | grep redmine drwxr-xr-x 11 www-data www-data 4096 8月 26 14:26 redmine
ちなみにapache2のユーザーの確認方法は以下。/etc/apache2/envvars
に変数として格納されている。
▶less /etc/apache2/envvars # settings are defined via environment variables and then used in apache2ctl, # /etc/init.d/apache2, /etc/logrotate.d/apache2, etc. export APACHE_RUN_USER=www-data # ←これ export APACHE_RUN_GROUP=www-data # ←これ ...
権限を変更してアクセスすると、、、
Win!
まとめ
先人様たちの記事のおかげで割とすんなりRedmine構築できた。
等々やってみたいなあ。