ページ

2013年12月30日月曜日

Ruby On Rails アプリケーション作成 2 - カレンダー表示 -

とりあえず・・カレンダーを表示してみる

完成イメージでは、初回表示画面にでーんとカレンダーが表示されていて、
今月の集計〜とかが表示されているイメージなので、カレンダーを表示してみる。

http://blog.scimpr.com/2013/01/25/rails3-2でgoogle-calendarライクなカレンダーを使う〜fullcalendar-rails/
上記サイトを参考にfullcalendar-railsなるものをインストール。

この中で出てくる「アセットパイプライン」曖昧だったので調査。
http://rails.hatenadiary.jp/entry/2013/03/03/125801

サイト内に書かれている
group :assets do
  gem ‘fullcalendar-rails’
end
この部分。どうやらrails4からはgroup :assets do が無くなったらしい。
http://stackoverflow.com/questions/16406204/why-did-rails4-drop-support-for-assets-group-in-the-gemfile

本家サイトを参考にGemfileに以下を追加
gem 'fullcalendar-rails'
bundle installコマンドで、gem環境にインストール。
後は、application.js, application.cssともにfullcalendar-railsを読み込む様にサイトを参考に
追加。

表示してみる・・うまくカレンダーが表示されました。

⬇️最終的なstates.js.coffee
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
$ ->
  $('#calendar').fullCalendar
    header:
      right: 'agendaDay agendaWeek month today prev next'
    titleFormat:
      month: 'yyyy年 MMMM'
    monthNames: [
      '1月'
      '2月'
      '3月'
      '4月'
      '5月'
      '6月'
      '7月'
      '8月'
      '9月'
      '10月'
      '11月'
      '12月'
    ]
    dayNamesShort: [
      '日'
      '月'
      '火'
      '水'
      '木'
      '金'
      '土'
    ]
    buttonText:
      today: '今日'
      month: '月'
      week: '週'
      day: ‘日'

色々cssもそれっぽいものに変更。












配色時に参考にしたサイト⬇️
http://www.find-job.net/startup/color-scheme-for-non-designer

とりあえずはいい感じ♪

次は集計欄をexcel風な感じにできたらな〜⬇️
http://programming-10000.hatenadiary.jp/entry/20130702/1372776366

2013年12月29日日曜日

Ruby On Rails アプリケーション作成 1 - RVMインストール -

何を作るか

今回気持ちを新たにrailsアプリケーションを作ってみる。。が!
何を作ろうかと思っていましたら、ちょうど昔作った「家計簿アプリ」を
スマホでも見たいという話もあって、WEBアプリケーションとして作成しようと
決めました。

まずは、、

環境が若干古いので、全てアップデート。
【現在の環境】
Mac Book Air
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin12.2.0]
$ rails -v
Rails 3.0.17

古いなあorz。でも前のバージョンを使ってなんやかんやする時もあるかもしれないので、
色んなRubyのバージョンを管理してくれる、RVMを使用する。

上記サイトを参考に、RVMをインストール。

$ git clone --depth 1 git://github.com/wayneeseguin/rvm.git
Cloning into 'rvm'...
remote: Counting objects: 502, done.
remote: Compressing objects: 100% (389/389), done.
remote: Total 502 (delta 41), reused 381 (delta 38)
Receiving objects: 100% (502/502), 1.06 MiB | 235.00 KiB/s, done.
Resolving deltas: 100% (41/41), done.
Checking connectivity... done
$ ls
rvm tig
$ cd rvm
$ ls
CONTRIBUTING.md VERSION lib
FORMATTING.md bin man
HACKING.md binscripts patches
History.txt config patchsets
LICENCE contrib rvm-test
NEXT.md examples rvm-test-rvm1
README gemsets scripts
README.rdoc help update-remote.sh
README.txt hooks
Rakefile install
$ ./install

Installing RVM to /Users/{ユーザ名}/.rvm/
    Adding rvm PATH line to /Users/{ユーザ名}/.profile /Users/{ユーザ名}/.bashrc /Users/{ユーザ名}/.zshrc.
    RVM sourcing line found in /Users/{ユーザ名}/.bash_profile.
    RVM sourcing line not found for Zsh, run the installer with '--auto-dotfiles' to fix it.
Installation of RVM in /Users/{ユーザ名}/.rvm/ is almost complete:

  * To start using RVM you need to run `source /Users/{ユーザ名}/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

# XXXXXXXXX,
#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.

In case of problems: http://rvm.io/help and https://twitter.com/rvm_io
       Help RVM 2.0: https://www.bountysource.com/fundraisers/489-rvm-2-0

  * WARNING: You have '~/.profile' file, you might want to load it,
    to do that add the following line to '/Users/{ユーザ名}/.bash_profile':

      source ~/.profile



インストール確認の為、rvm infoを実行
$ rvm info

system:

  system:
    uname:       "Darwin MacBook-Air.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64"
    system:      "osx/10.9/x86_64"
    bash:        "/bin/bash => GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)"
    zsh:         "/bin/zsh => zsh 5.0.2 (x86_64-apple-darwin13.0)"

  rvm:
    version:      "rvm 1.25.8 (manual) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
    updated:      "31 seconds ago"
    path:         "/Users/{ユーザ名}/.rvm"

  homes:
    gem:          "not set"
    ruby:         "not set"

  binaries:
    ruby:         "/Users/{ユーザ名}/.rbenv/shims/ruby"
    irb:          "/Users/{ユーザ名}/.rbenv/shims/irb"
    gem:          "/Users/{ユーザ名}/.rbenv/shims/gem"
    rake:         "/Users/{ユーザ名}/.rbenv/shims/rake"

  environment:
    PATH:         "/usr/local/heroku/bin:/Users/{ユーザ名}/.rbenv/shims:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/Users/{ユーザ名}/.rvm/bin"
    GEM_HOME:     ""
    GEM_PATH:     ""
    MY_RUBY_HOME: ""
    IRBRC:        ""
    RUBYOPT:      ""
    gemset:       ""


うまくインストールされたっぽい。
次にruby 2.0.0をインストール。
$ rvm install 2.0.0
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.9/x86_64/ruby-2.0.0-p353.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Installing requirements for osx.
Updating system................................................................
Installing required packages: autoconf, automake, libtool, libyaml, libksba....
Updating certificates in '/usr/local/etc/openssl/cert.pem'.
Requirements installation successful.
Installing Ruby from source to: /Users/{ユーザ名}/.rvm/rubies/ruby-2.0.0-p353, this may take a while depending on your cpu(s)...
ruby-2.0.0-p353 - #downloading ruby-2.0.0-p353, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10.2M  100 10.2M    0     0  1093k      0  0:00:09  0:00:09 --:--:-- 1065k
ruby-2.0.0-p353 - #extracting ruby-2.0.0-p353 to /Users/{ユーザ名}/.rvm/src/ruby-2.0.0-p353.
ruby-2.0.0-p353 - #configuring.................................................
ruby-2.0.0-p353 - #post-configuration.
ruby-2.0.0-p353 - #compiling.............................................................-
ruby-2.0.0-p353 - #installing...............
ruby-2.0.0-p353 - #making binaries executable.
ruby-2.0.0-p353 - #downloading rubygems-2.2.0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  400k  100  400k    0     0   755k      0 --:--:-- --:--:-- --:--:--  755k
ruby-2.0.0-p353 - #extracting rubygems-2.2.0.
ruby-2.0.0-p353 - #removing old rubygems.
ruby-2.0.0-p353 - #installing rubygems-2.2.0..
ruby-2.0.0-p353 - #gemset created /Users/{ユーザ名}/.rvm/gems/ruby-2.0.0-p353@global
ruby-2.0.0-p353 - #importing gemset /Users/{ユーザ名}/.rvm/gemsets/global.gems......|
ruby-2.0.0-p353 - #generating global wrappers.
ruby-2.0.0-p353 - #gemset created /Users/{ユーザ名}/.rvm/gems/ruby-2.0.0-p353
ruby-2.0.0-p353 - #generating default wrappers.
ruby-2.0.0-p353 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.0.0-p353 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri
$ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin13.0.0]

ruby 2.0.0がインストールされました。
次にrailsのインストールですが、rvmにはrailsの環境を整えるのに便利なgemsetというのが
あるらしいです。

新しいruby 2.0.0のgem環境なので、上記サイトにあるようにあまりgemが入ってないかと
思いきや、なんやかんや入っていました。
$ which ruby
/Users/{ユーザ名}/.rvm/rubies/ruby-2.0.0-p353/bin/ruby
$ gem list

*** LOCAL GEMS ***

bigdecimal (1.2.0)
bundler (1.5.1)
bundler-unload (1.0.2)
executable-hooks (1.2.6)
gem-wrappers (1.2.1)
io-console (0.4.2)
json (1.7.7)
minitest (4.3.2)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
rubygems-bundler (1.4.2)
rvm (1.11.3.8)
test-unit (2.0.0.0)
$ which gem
/Users/{ユーザ名}/.rvm/rubies/ruby-2.0.0-p353/bin/gem

rails用に新規のgemsetを作成。
$ rvm gemset list

gemsets for ruby-2.0.0-p353 (found in /Users/{ユーザ名}/.rvm/gems/ruby-2.0.0-p353)
=> (default)
   global

$ rvm gemset create rails40
ruby-2.0.0-p353 - #gemset created /Users/{ユーザ名}/.rvm/gems/ruby-2.0.0-p353@rails40
ruby-2.0.0-p353 - #generating rails40 wrappers.
$ rvm gemset list

gemsets for ruby-2.0.0-p353 (found in /Users/{ユーザ名}/.rvm/gems/ruby-2.0.0-p353)
=> (default)
   global
   rails40


作成した環境へ切り替える。
$ rvm 2.0.0@rails40
$ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin13.0.0]
$ rvm gemset list

gemsets for ruby-2.0.0-p353 (found in /Users/{ユーザ名}/.rvm/gems/ruby-2.0.0-p353)
   (default)
   global
=> rails40


この環境のgemにrailsをインストールする。
$ rails -v
Rails 4.0.2
無事railsをインストール。
新規プロジェクト作成し、起動を確認。ん〜なんとかうまくいってる感じ。




2013年12月26日木曜日

Gitでのパッチファイル作成、適用

パッチファイルの作成


git diff --no-prefix HEAD~1 > thisis.patch

上記コマンドにてHEADから1つ前までの差分パッチファイルをthisis.patchファイルに作成する


パッチファイルの確認


$ patch --dry-run -p0 < thisis.patch

 上記コマンドにて実際にはパッチを当てないけど、当てた場合に問題無いかを確認


パッチを当てる


$ patch -p0 < thisis.patch

 上記コマンドで実際にパッチを当てる


参考サイト
http://d.hatena.ne.jp/kanonji/20110222/1298341934

2013年12月23日月曜日

RaspberryPiと戯れてみる 8 - マウント -

ルータのプチNASディレクトリをRasppbery Pi上からマウント


https://sites.google.com/site/iroironeuromag/linuxgarami/-linuxkarawindows-nas-ni-jie-xusuru
ここら辺を参考にコマンド実行

mount.cifs: bad UNC
 
とかで怒られるorz
 
パスの指定が¥になっていたので、/に直して再度実行。
 
sudo mount -t cifs //192.168.0.1/baffalo-1 /nas/baffalo
 
今度はうまく行きました^_^
 

2013年11月30日土曜日

RaspberryPiと戯れてみる 7 - VPN再チャレンジ -

VPN再チャレンジ!!


有識者の方のありがたい助言をいただき、どうもdocomoの回線からVPN接続した場合
PPTPをサポートしていなさげらしいorz。

なので、「L2PTを使用するべし」というお言葉を頂きました。

・L2PT  http://e-words.jp/w/L2TP.html
・PPP http://e-words.jp/w/PPP.html

先生に聞いてみると以下参考サイトを発見
http://www.majishini.net/wp/?p=394

まずは、IPアドレスを固定で使用する様に設定。
参考サイト
http://www.hiramine.com/physicalcomputing/raspberrypi/setup_staticip.html

pi@raspberrypi /etc/network $ diff interfaces interfaces.org
4,7c4
< iface eth0 inet static
< address 192.168.0.4
< netmask 255.255.255.0
< gateway 192.168.0.1
---

> iface eth0 inet dhcp

sysctl.congの編集と反映

pi@raspberrypi /etc $ sudo vi sysctl.conf
pi@raspberrypi /etc $ sudo sysctl -p
kernel.printk = 3 4 1 3
vm.swappiness = 1
vm.min_free_kbytes = 8192
net.ipv4.ip_forward = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.eth0.send_redirects = 0
net.ipv4.conf.eth0.accept_redirects = 0
net.ipv4.conf.lo.send_redirects = 0

net.ipv4.conf.lo.accept_redirects = 0

/etc/ipsec.confの編集

pi@raspberrypi /etc $ sudo cp -p ipsec.conf ipsec.conf.org
pi@raspberrypi /etc $ sudo vi ipsec.conf
pi@raspberrypi /etc $ diff ipsec.conf ipsec.conf.org 
43,61d42
< conn L2TP
<        keyingtries=0
<        type=transport
<        compress=yes
<        authby=secret
<        forceencaps=yes
<        pfs=no
<        auto=add
<        ike=aes-sha1;modp3072
<        phase2=esp
<        phase2alg=aes-sha1;modp3072
<        rekey=no
<        salifetime=3h
<        ikelifetime=1h
<        left=192.168.0.4 # Raspberry PiのIPアドレスにする
<        leftprotoport=17/1701
<        right=%any
<        rightprotoport=17/%any
pi@raspberrypi /etc $ 

/etc/ipsec.secretsの編集

pi@raspberrypi /etc $ sudo diff ipsec.secrets ipsec.secrets.org
11,12d10
< 192.168.0.4 %any: PSK "XXXXXX"
pi@raspberrypi /etc $ 

openswan再起動とベリファイチェック

pi@raspberrypi /etc $ sudo service ipsec restart
ipsec_setup: Stopping Openswan IPsec...
ipsec_setup: Starting Openswan IPsec 2.6.37...
ipsec_setup: No KLIPS support found while requested, desperately falling back to netkey
ipsec_setup: NETKEY support found. Use protostack=netkey in /etc/ipsec.conf to avoid attempts to use KLIPS. Attempting to continue with NETKEY
pi@raspberrypi /etc $ sudo ipsec verify
Checking your system to see if IPsec got installed and started correctly:
Version check and ipsec on-path                             [OK]
Linux Openswan U2.6.37/K3.6.11+ (netkey)
Checking for IPsec support in kernel                        [OK]
 SAref kernel support                                       [N/A]
 NETKEY:  Testing XFRM related proc values                  [OK]
[OK]
[OK]
Checking that pluto is running                              [OK]
 Pluto listening for IKE on udp 500                         [OK]
 Pluto listening for NAT-T on udp 4500                      [OK]
Checking for 'ip' command                                   [OK]
Checking /bin/sh is not /bin/dash                           [WARNING]
Checking for 'iptables' command                             [OK]
Opportunistic Encryption Support                            [DISABLED]

xl2tpdの設定

pi@raspberrypi /etc/xl2tpd $ sudo vi xl2tpd.conf
pi@raspberrypi /etc/xl2tpd $ sudo diff xl2tpd.conf xl2tpd.conf.org 
77,86d76
< [global]
< port = 1701
< [lns default]
< ip range = 192.168.0.201 - 192.168.0.210
< local ip = 192.168.0.4
< length bit = yes
< refuse chap = yes
< require authentication = yes
< pppoptfile = /etc/ppp/l2tpd.pppopt
pi@raspberrypi /etc/xl2tpd $ 

pppoptfileの作成

pi@raspberrypi /etc/xl2tpd $ sudo vi /etc/ppp/l2tpd.pppopt
pi@raspberrypi /etc/xl2tpd $ sudo cat /etc/ppp/l2tpd.pppopt
asyncmap 0
auth
crtscts
lock
modem
debug
proxyarp
lcp-echo-interval 180
lcp-echo-failure 3

refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2

ms-dns 192.168.0.1

pppd認証の設定

pi@raspberrypi /etc/ppp $ sudo diff chap-secrets chap-secrets.org 
3c3
< XXXXXX * XXXXXX *
---
pi@raspberrypi /etc/ppp $ 

自宅ルータの設定









あとはAndroid端末から接続・・・

うまく繋がりました!!

























☝️自宅Raspberry Piのredmineへ接続している様子
ここまで長かった〜orz

ついでにファイルサーバもインストール

sambaを導入。

参考サイト
http://assimane.blog.so-net.ne.jp/2013-03-30

pi@raspberrypi ~ $ sudo apt-get install samba
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下の特別パッケージがインストールされます:
  tdb-tools
提案パッケージ:
  openbsd-inetd inet-superserver smbldap-tools ldb-tools ctdb
以下のパッケージが新たにインストールされます:
  samba tdb-tools
アップグレード: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。
3,332 kB のアーカイブを取得する必要があります。
この操作後に追加で 20.1 MB のディスク容量が消費されます。
続行しますか [Y/n]? y
取得:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main samba armhf 2:3.6.6-6+deb7u1 [3,307 kB]
取得:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main tdb-tools armhf 1.2.10-2 [25.9 kB]
3,332 kB を 5秒 で取得しました (601 kB/s)
パッケージを事前設定しています ...
以前に未選択のパッケージ samba を選択しています。
(データベースを読み込んでいます ... 現在 70009 個のファイルとディレクトリがインストールされています。)
(.../samba_2%3a3.6.6-6+deb7u1_armhf.deb から) samba を展開しています...
以前に未選択のパッケージ tdb-tools を選択しています。
(.../tdb-tools_1.2.10-2_armhf.deb から) tdb-tools を展開しています...
man-db のトリガを処理しています ...
samba (2:3.6.6-6+deb7u1) を設定しています ...
Generating /etc/default/samba...
グループ `sambashare' (グループ ID 113) を追加しています...
完了。
update-alternatives: /usr/bin/smbstatus (smbstatus) を提供するために 自動モード で /usr/bin/smbstatus.samba3 を使います
[ ok ] Starting Samba daemons: nmbd smbd.
tdb-tools (1.2.10-2) を設定しています ...
update-alternatives: /usr/bin/tdbbackup (tdbbackup) を提供するために 自動モード で /usr/bin/tdbbackup.tdbtools を使います

pi@raspberrypi ~ $ 
pi@raspberrypi ~ $ sudo apt-get install samba-common-bin
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下のパッケージが新たにインストールされます:
  samba-common-bin
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
2,690 kB のアーカイブを取得する必要があります。
この操作後に追加で 15.9 MB のディスク容量が消費されます。
取得:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main samba-common-bin armhf 2:3.6.6-6+deb7u1 [2,690 kB]
2,690 kB を 3秒 で取得しました (866 kB/s)     
以前に未選択のパッケージ samba-common-bin を選択しています。
(データベースを読み込んでいます ... 現在 70100 個のファイルとディレクトリがインストールされています。)
(.../samba-common-bin_2%3a3.6.6-6+deb7u1_armhf.deb から) samba-common-bin を展開しています...
man-db のトリガを処理しています ...
samba-common-bin (2:3.6.6-6+deb7u1) を設定しています ...
update-alternatives: /usr/bin/nmblookup (nmblookup) を提供するために 自動モード で /usr/bin/nmblookup.samba3 を使います
update-alternatives: /usr/bin/net (net) を提供するために 自動モード で /usr/bin/net.samba3 を使います
update-alternatives: /usr/bin/testparm (testparm) を提供するために 自動モード で /usr/bin/testparm.samba3 を使います
pi@raspberrypi ~ $ 

設定ファイルの更新

pi@raspberrypi ~ $ sudo cp -p /etc/samba/smb.conf /etc/samba/smb.conf.org
pi@raspberrypi ~ $ sudo vi /etc/samba/smb.conf
pi@raspberrypi ~ $ sudo diff /etc/samba/smb.conf /etc/samba/smb.conf.org
334,341d333
< [share]
< comment = share drive
< read only = no
< locking = no
< path = /home/pi/share
< guest ok = yes
< force user = pi
pi@raspberrypi ~ $ 


パスワードの設定と再起動

pi@raspberrypi ~ $ sudo smbpasswd -a pi
New SMB password:
Retype new SMB password:
Added user pi.
pi@raspberrypi ~ $ sudo service samba restart
[ ok ] Stopping Samba daemons: nmbd smbd.
[ ok ] Starting Samba daemons: nmbd smbd.

パスワード : sanji

ドヤから確認し、無事アクセスできました。


iPad mini retina購入

思い切りすぎてiPad mini retina購入


色はスペースグレイ、容量は16Gのモデルを購入。
カバーは純正のSmart Coverにしてみました。また、Smart Cover自体が
全面しかカバーしてくれないので、Smart Coverと併用できる裏面カバーも
購入。



まったく関係ないハウステンボスで購入したシャンクスの旗と一緒に撮影。




カバーを開けるとこんな感じ。




Smart Coverはスタンドにもなるそうな。



現在の一番活用法はmac book air のマルチディスプレイとして活用。
両方にAirDisplayをインストール。

また、nasneに入っている番組をipadで見れたりする
Media Link Player for DTVもインストール。快適な感じ。

2013年11月24日日曜日

RaspberryPiと戯れてみる 6 - Redmine自動バックアップ -

redmineの自動バックアップ

redmineのバックアップには
・redmine/files
・database
のバックアップが必要
http://t2wonderland.blogspot.jp/2013/02/redmine-redmine.html

1. files配下のバックアップ

redmine/filesはどこにあるか探した所、
/var/lib/redmine/default/files
にありました。

pi@raspberrypi /usr/backup/redmine $ sudo tar -cvzf /usr/backup/redmine/files_`date +%Y%m%d`.tgz /var/lib/redmine/default/files
tar: メンバ名から先頭の `/' を取り除きます
/var/lib/redmine/default/files/
/var/lib/redmine/default/files/131124140554_Puzzle.xlsx
files配下をtarファイルに圧縮するコマンドを実行。
tarファイルが作成されています。

2. databaseのバックアップ

参考サイトを元にダンプファイルを作成するコマンドを実行してみた所、
pi@raspberrypi /usr/backup/redmine $ sudo mysqldump -uredmine -pspice redmine > ./db_`date +%Y%m%d`.dump
mysqldump: Got error: 1045: ユーザー 'redmine'@'localhost' を拒否します.uUsing password: YES) when trying to connect

怒られてしまいましたorz。
はて?な感じなので普通にログインしてみる
pi@raspberrypi /usr/backup/redmine $ mysql -uredmine -pXXXX
ERROR 1045 (28000): ユーザー 'redmine'@'localhost' を拒否します.uUsing password: YES)

パスワードが違うとの事ですが、パスワードは合っています。

pi@raspberrypi /usr/backup/redmine $ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 50
Server version: 5.5.31-0+wheezy1 (Debian)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user, host, password from user;
ERROR 1046 (3D000): データベースが選択されていません.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| redmine_default    |
| test               |
+--------------------+
5 rows in set (0.01 sec)

mysql> use redmine_default;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user, host, password from user;
ERROR 1146 (42S02): Table 'redmine_default.user' doesn't exist
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user, host, password from user;
+------------------+-------------+-------------------------------------------+
| user             | host        | password                                  |
+------------------+-------------+-------------------------------------------+
| root             | localhost   | *7E4342FF084A70DD409EAB26EC7F6360D80F12BC |
| root             | raspberrypi | *7E4342FF084A70DD409EAB26EC7F6360D80F12BC |
| root             | 127.0.0.1   | *7E4342FF084A70DD409EAB26EC7F6360D80F12BC |
| root             | ::1         | *7E4342FF084A70DD409EAB26EC7F6360D80F12BC |
|                  | localhost   |                                           |
|                  | raspberrypi |                                           |
| debian-sys-maint | localhost   | *24EC3DF32614F55A010429412599E3D93437737E |
| redmine_default  | localhost   | *3BA1B4133A1E16B59311B1B379C2E78F19627CFE |
+------------------+-------------+-------------------------------------------+
8 rows in set (0.00 sec)

mysql> quit;
Bye
rootでmysqlへログインし、設定されているユーザ名とパスワード一覧を表示してみる事に
すると「redmine」ではなく「redmine_default」らしい。

これをふまえてmysqlのダンプ出力コマンドは、
pi@raspberrypi /usr/backup/redmine $ sudo mysqldump -uredmine_default -pXXXX redmine_default > ./db_`date +%Y%m%d`.dump
でダンプ出力ができました。

cronでバックアップしようと思ったのですが、今は未だ24時間起動しっぱなしでは無い為、
手動で行う事にしました。
ログイン時に自動でバックアップしてくれるように ~/.profileを編集
sudo /usr/backup/redmine/backup_redmine.sh
上記を一番下に追加しました。
これでpiユーザでログインする度に自動でバックアップが行われます。

2013年11月9日土曜日

RaspberryPiと戯れてみる 5 - Redmine SCM Repository Creation Plugin -

Redmine関連調査


前回、SCM Repository Creation pluginをインストールしてみたが、
リポジトリが作成できない。

そこでログを見てみる事に。
/var/log/redmine/default/production.log

Processing RepositoriesController#create (for 192.168.0.4 at 2013-11-09 10:25:32) [POST]
  Parameters: {"authenticity_token"=>"MKNJS+kSPag72DRzkCOd1c8JqoZO/jO07K7cWl3mgPw=", "repository_scm"=>"Git", "repository"=>{"is_default"=>"1", "identifier"=>"bibo", "url"=>"/var/www/repos/git/bibo-rock.git.0", "path_encoding"=>"", "extra_report_last_commit"=>"0"}, "commit"=>"リポジトリの作成", "operation"=>"add", "controller"=>"repositories", "action"=>"create", "project_id"=>"bibo-rock"}
Creating reporitory: /var/www/repos/git/bibo-rock.git.0.git

NoMethodError (undefined method `created_with_scm=' for #<Repository::Git:0x2544db0>):
  /usr/lib/ruby/vendor_ruby/active_record/attribute_methods.rb:270:in `method_missing'
  /usr/lib/ruby/vendor_ruby/action_controller/base.rb:1333:in `perform_action'
  /usr/lib/ruby/vendor_ruby/action_controller/filters.rb:617:in `call_filters'
  /usr/lib/ruby/vendor_ruby/action_controller/filters.rb:610:in `perform_action_with_filters'

NoMethodErrorが出ている?
google先生に聞いてみると、
rake redmine:plugins:migrate RAILS_ENV=production
このコマンドを実行してないのでは?というが前回実行したはず。
もう一度実行。するとabortしているorz
どうやらコマンドがredmineのバージョンによって異なるみたい。
http://stackoverflow.com/questions/13194653/rake-redminepluginsmigrate-is-not-executing

正しいコマンドで実行。
pi@raspberrypi /usr/share/redmine $ sudo rake db:migrate_plugins RAILS_ENV=production
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /usr/share/redmine/vendor/rails/railties/lib/rails/gem_dependency.rb:21.
Migrating engines...
Migrating acts_as_activity_provider...
Migrating acts_as_attachable...
Migrating acts_as_customizable...
Migrating acts_as_event...
Migrating acts_as_list...
Migrating acts_as_searchable...
Migrating acts_as_tree...
Migrating acts_as_versioned...
Migrating acts_as_watchable...
Migrating awesome_nested_set...
Migrating classic_pagination...
Migrating gravatar...
Migrating open_id_authentication...
Migrating prepend_engine_views...
Migrating redmine_scm...
==  AddRepositoriesCreatedWithScm: migrating ==================================
-- add_column(:repositories, :created_with_scm, :boolean, {:default=>false, :null=>false})
   -> 0.1317s
==  AddRepositoriesCreatedWithScm: migrated (0.1355s) =========================

Migrating rfpdf...

どうやらうまくいったっぽい?
redmine上からgitリポジトリを作成。すると・・・見事作成できました!!













redmineとgitの連携
http://d.hatena.ne.jp/CortYuming/20120430/p1
上記のサイトを参考に実施

2013年11月5日火曜日

RaspberryPiと戯れてみる 4 - Redmine導入 -

再OSインストール


色々ごちゃごちゃしてしまったので、一度クリーンな状態に戻そうとして、
OSを再インストールした時のメモ。

初回と同じ様にRPi-sd card builder v1.2.appを使用してSDカードに
書き込もうとしたらエラーが出てしまった。

「アクション“シェルスクリプトを実行 (Image to Card)”でエラーが起きました。
アクションの設定を確認してから、ワークフローをもう一度実行してください。」

以下サイトを参考にターミナルから直接書き込む
http://yohtn.hatenablog.com/entry/2013/07/18/154622

$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *251.0 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            250.1 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *15.8 GB    disk1
   1:                 DOS_FAT_32 PI                      58.7 MB    disk1s1
   2:                      Linux                         15.7 GB    disk1s2
$ sudo dd bs=1m if=/Users/{ユーザ名}/Documents/develop/Raspberry Pi/OS Install/2013-07-26-wheezy-raspbian.img of=/dev/disk1
dd: unknown operand Pi/OS
$ sudo dd bs=1m if=/Users/{ユーザ名}/Documents/develop/Raspberry_Pi/OS_Install/2013-07-26-wheezy-raspbian.img of=/dev/disk1
dd: /dev/disk1: Resource busy
$ sudo umount /dev/disk1
umount: /dev/disk1: not currently mounted
$ sudo mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
/dev/disk1s1 on /Volumes/PI (msdos, local, nodev, nosuid, noowners)
$ umount /Volumes/PI
umount: unmount(/Volumes/PI): Operation not permitted
$ sudo umount /Volumes/PI
$ sudo dd bs=1m if=/Users/{ユーザ名}/Documents/develop/Raspberry_Pi/OS_Install/2013-07-26-wheezy-raspbian.img of=/dev/disk1
1850+0 records in
1850+0 records out
1939865600 bytes transferred in 301.820387 secs (6427219 bytes/sec)

なんとか書き込めたっぽい?
ssh で接続 ・・・ IPが変わってしまっているが、気にしない。
rootユーザのパスワードを設定します。
?
pi@raspberrypi:~$ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
pi@raspberrypi:~$

sudo raspi-config 初期設定
以下サイトを参考に実行
http://netbuffalo.doorblog.jp/archives/4578498.html

Redmineを導入してみる


1. mysqlをインストール
2. redmine用のmysqlパスワードを設定
3. http://IPアドレス/redmineでアクセス

とりあえず、起動してブラウザから操作できる事を確認。
んで、バージョン管理ツールとの連携をすべく、「Redmine SCM Creator」
なるプラグインをインストール。
http://mistymagich.wordpress.com/2011/10/19/redmine_and_subversion-git-mercurial-repository/

が、リポジトリ作成ができないorz  要調査。