Archive for: 󈥬月 2011’

crontab 覚え書き

2011年12月29日 Posted by PURGE

久しぶりに cron の設定。忘れていたので覚え書き。
-l で一覧。 -e で編集。

$crontab -l 
0 0  * * * /opt/scripts/svn_backup.sh
0 0  * * * /opt/scripts/mysql_backup.sh

左から、分 0~59 / 時 0~23 / 日 1~31 / 月 1~12 / 曜日 0~7

JDK1.6のインストールとAlternatives

2011年12月21日 Posted by PURGE

毎回インストール方法が簡単になるけど、反面ブラックボックス化して理解不能になるので覚え書き。

ここから、jdk-6u30-linux-x64.bin をダウンロードして解凍。
ちなみに、jdk-6u30-linux-x64-rpm.bin は勝手にインストールしてくれるので、自分的にはNG。

余談だが、X86 と X64 は、64bit版がX64で、32bit版がX86。
数値の大小がまぎらわしい。 Windows7 と Windows98 みたいなもの・・・。

[user@server src]$ sudo ./jdk-6u30-linux-x64.bin
Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
   creating: jdk1.6.0_30/
   creating: jdk1.6.0_30/db/
   creating: jdk1.6.0_30/db/bin/
  inflating: jdk1.6.0_30/db/bin/ij

…省略

Creating jdk1.6.0_30/jre/lib/ext/localedata.jar
Creating jdk1.6.0_30/jre/lib/plugin.jar
Creating jdk1.6.0_30/jre/lib/javaws.jar
Creating jdk1.6.0_30/jre/lib/deploy.jar

Java(TM) SE Development Kit 6 successfully installed.

Product Registration is FREE and includes many benefits:
* Notification of new versions, patches, and updates
* Special offers on Oracle products, services and training
* Access to early releases and documentation

Product and system data will be collected. If your configuration
supports a browser, the JDK Product Registration form will
be presented. If you do not register, none of this information
will be saved. You may also register your JDK later by
opening the register.html file (located in the JDK installation
directory) in a browser.

For more information on what data Registration collects and
how it is managed and used, see:
http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html

Press Enter to continue.....

Done.

解凍されたディレクトリを、お好みの場所へ移動。

[user@server src]$ sudo mv jdk1.6.0_30 /usr/local/jdk1.6
[user@server src]$ ls /usr/local/jdk1.6/

javaのバージョンを調べると古いまま・・・。
どうやらalternatives というもので管理されているよう。
OS初期状態では、/usr/lib/jvm/jre-1.4.2-gcj/bin/java が実態としてリンクされている模様。

[root@servere ~]# alternatives --config java

1 プログラムがあり 'java' を提供します。

  選択       コマンド
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java

Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:

alternatives –install で、今回インストールしたディレクトリを指定する。
ちなみに、最後の30は優先順位らしいが、いくつでもよい。指定しないと怒られる。

[root@server ~]# alternatives --install /usr/bin/java java /usr/local/jdk1.6/bin/java 30
[root@server ~]# alternatives --config java

2 プログラムがあり 'java' を提供します。

  選択       コマンド
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
   2           /usr/local/jdk1.6/bin/java

Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2

どうやら上手くいったようだ。

ちなみに、ユーザは /usr/bin/java を環境変数のパスで参照しに行っている。
/usr/bin/java → /etc/alternatives/java → /usr/local/jdk1.6/bin/java

慣れれば便利だが、知らないと手動で ln -s してしまいそう。
下記のコマンドは、alternativesを使用しているようなので気を付けよう。

antlr              ksh             mta-newaliases     print-cancel     print-lpqman
java               ksh-man         mta-newaliasesman  print-cancelman  print-lprm
jaxp_parser_impl   ksh-usrbin      mta-pam            print-lp         print-lprman
jre_1.4.2          mta             mta-rmail          print-lpc        print-lprmman
jre_1.4.2_exports  mta-aliasesman  mta-sendmail       print-lpcman     print-lpstat
jre_gcj            mta-mailq       mta-sendmailman    print-lpman      print-lpstatman
jre_gcj_exports    mta-mailqman    print              print-lpq        xinputrc

Oracleインスタンス起動方法

2011年12月21日 Posted by PURGE

今更ながら、Oracleインスタンス起動方法

[oracle@server ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 水 12月 21 15:36:49 2011

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

アイドル・インスタンスに接続しました。

SQL> startup
ORACLEインスタンスが起動しました。

Total System Global Area 1.0088E+10 bytes
Fixed Size                  2215984 bytes
Variable Size            6710890448 bytes
Database Buffers         3355443200 bytes
Redo Buffers               19640320 bytes
データベースがマウントされました。
データベースがオープンされました。

jQuery Plugin 事始め その2

2011年12月21日 Posted by PURGE

以前の記事で、jQueryのプラグインを簡単に作成してみたが、まだまだ融通が利かない。

そこで、いろんなライブラリを解読してみて、そこそこ使える形式が見えてきたので記載する。
この記述方法だと、内部からも外部からも関数をコールできるので、後にパラメータを渡すことができる。

jquery.sample.js

 
/*
 * 自作プラグインサンプル
 */
;(function($){
	var sample = function(target, opts){
		//デフォルトパラメータ
		this.defaults = {
	        param : 'hoge',
	        params : [{title : 'DefTitle1', name: 'DefName1', id: '111' },
	                  {title : 'DefTitle2', name: 'DefName2', id: '222' }
	                 ],
	        width :  '1200px'
		}
		//パラメータ上書き
		$.extend(this.defaults, opts || {});
		
		//関数コール
		this.init();
		this.reload(this.defaults.width);
	
	}
	//関数定義
	sample.prototype = {
		init: function() {
			alert("Init:" + this.defaults.param);
		},
		reload: function(str) {
			alert("Reload:" + str);
		}
	};

	//-----------------
	// エントリポイント
	//-----------------
    $.fn.sample = function(options){
	    //オプション取得
	    opts = jQuery.extend({}, $.fn.sample.defaults, options);
	
//	    return this.each(function(){
//			new sample(this, options, temp);
//		});
		
		if ( $(this).length > 1) {
			var _instances = [];
			$(this).each(function(i) {
				_instances[i] = new sample(this, options);
			});
			return _instances;
		} else {
			return new sample(this, options);
		}
    };
    
	//-----------------
    //デフォルト値
	//-----------------
//    $.fn.sample.defaults = {
//        param : 'hoge',
//        params : [{title : 'defTitle1', name: 'defName1', id: '111' },
//                  {title : 'defTitle2', name: 'defName2', id: '222' }
//                 ],
//        width :  '1200px'
//    };
})(jQuery);    

コールする側 [HTML]

<script type="text/javascript">
$("#sample").sample({param:'moge'}).reload('hage!!');
</script>
<div id="sample"></div>

但し、十分な検証はしていないので、自己責任で参考にしてください。

Gemfile WindowsXP(開発機) ⇔ CentOS5.5 デプロイ

2011年12月17日 Posted by PURGE

サーバ(CentOS5.5)側と、開発機(WindowsXP SP3)でどうしてもgem等バージョンの整合性を合わせるのが大変だった。ruby初級者なので、理解も曖昧・・・。

こちらを立てるとあちらが立たずという感じ。苦痛。

ハマッたのは、execjs と therubyracerの指定。
なぜかpythonのライブラリを求められたりしたので…。

とりあえず最終形としての Gemfile

source 'http://rubygems.org'
gem 'rails', '3.1.3'

# Bundle edge Rails instead:
# gem 'rails',     :git =&gt; 'git://github.com/rails/rails.git'

gem 'mysql2', '0.3.10'

gem 'rake', '0.8.7'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'execjs'
  gem 'therubyracer', :platforms =&gt; :ruby
  gem 'sass-rails',   '~&gt; 3.1.5'
  gem 'coffee-rails', '~&gt; 3.1.1'
  gem 'uglifier', '&gt;= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~&gt; 3.0.0'
# Use unicorn as the web server
# gem 'unicorn'

#group :development do
# Deploy with Capistrano
# gem 'capistrano', requier =&gt; nil
# gem 'capistrano-ext', requier =&gt; nil
# To use debugger
# gem 'ruby-debug19', :require =&gt; 'ruby-debug'
#end

group :test do
  # Pretty printed test output
  gem 'turn', '0.8.2', :require =&gt; false
end

試行錯誤の結果なので、正しい設定かは責任は一切持ちません。とりあえず動作したというだけの設定。これから色々理解していこうと思います。
参考にするなら、独自環境に合わせてください。責任は持ちません。

Capistrano deployエラー

2011年12月17日 Posted by PURGE

WindowsXPクライアント開発機から、CentOS5.5サーバへcapstrano で下記エラー。
Ruby 1.9.3 will raise SystemCallError in this case

デプロイ設定で丸1日程ハマっている…。

$ cap deploy      
  * executing `deploy'
  * executing `deploy:update'
 ** transaction: start
  * executing `deploy:update_code'
    executing locally: "svn info http://svn.server.host/repos/xxxx --username hoge --password hoge --no-auth-cache  -rHEAD"
c:/ruby1.9.2/lib/ruby/gems/1.9.1/gems/capistrano-2.9.0/lib/capistrano/recipes/deploy.rb:97:
 warning: failed to set environment variable. 
Ruby 1.9.3 will raise SystemCallError in this case.
*** [deploy:update_code] rolling back
  * executing "rm -rf /app/xxxx/releases/20111217022544; true"
    servers: ["svn.server.host"]
Password:
    [svn.server.host] executing command
    command finished in 422ms
c:/ruby1.9.2/lib/ruby/gems/1.9.1/gems/capistrano-2.9.0/lib/capistrano/recipes/deploy.rb:106:in ``': 
No such file or directory - svn info http://svn.server.host/repos/xxxx --username hoge --password hoge --no-auth-cache -rHEAD (Errno::ENOENT)
        from c:/ruby1.9.2/lib/ruby/gems/1.9.1/gems/capistrano-2.9.0/lib/capistrano/recipes/deploy.rb:106:in `block in run_locally'

Capstranoのデプロイ時、サーバ上でsvnコマンドを発行していると思い込んでいたのだが、WindowsXPクライアント開発機でコマンドラインでの問題のようだと疑ってみる。

クライアント開発機でSVNコマンドライン実行できないとダメなのか?
TortuiseSVN はインストール済みだし、 CapstranoをインストールしていればクライアントからのSVN取得は問題ないと勝手に思い込んでいた。
とにかく、SVN CLI で検索してみて1番上に引っ掛かった下記ツールをダウンロード&インストールしてみた。

sliksvn

$ cap deploy
  * executing `deploy'
  * executing `deploy:update'
 ** transaction: start
  * executing `deploy:update_code'
    executing locally: "svn info http://svn.server.host/repos/xxxx --username hoge --password hoge --no-auth-cache  -rHEAD"
    command finished in 2406ms

とりあえずのエラー回避。

Capistrano のエラー

2011年12月15日 Posted by PURGE

デプロイの為、Capistrano を使ってみる。
環境は、WindowsXP のクライアント開発環境から、CentOS5.5 のリモートサーバ上へ。

まずは、クライアント開発環境にて、capistrano を gemでインストール。

$ gem install capistrano
$ gem install capistrano-ext

クライアント開発機のアプリのフォルダへ移動して、capifyコマンド。

$ capify .
[add] writing './Capfile'
[add] writing './config/deploy.rb'
[done] capified!

まずは、sshで怒られる。ログインユーザがwindowsのユーザ名(xxxx)になっていた。

$ cap deploy:setup
  * executing `deploy:setup'
Password:
connection failed for: www.whoocus.com 
(Net::SSH::AuthenticationFailed: xxxx)

capify で生成された deploy.rb に追記。

set :user, "app"

今度は、sudoコマンドは、tty でなければならないと怒られる。

$ cap deploy:setup
  * executing `deploy:setup'
Password:
[****] sudo: sorry, you must have a tty to run sudo

サーバ側で、visudo にてsudo のデフォルト設定を変更しなくてはならない。

# コメントアウト
#Defaults    requiretty

またも怒られる。

$ cap deploy:setup
  * executing `deploy:setup'
Password:
 no tty present and no askpass program specified

再度、サーバ側で、visudo にてsudo のデフォルト設定を追記。

# 追記
Defaults    visiblepw

リモートサーバ上に、デプロイ用のディレクトリができている。
やっとうまく行った。

sudo ユーザ

2011年12月14日 Posted by PURGE

sudo コマンドが利用できるようにユーザを設定

# usermod -G wheel 新しいユーザ

/etc/group ファイルに追加されているはず。

# view /etc/group

ActionView::Template::Error (application.css isn’t precompiled):

2011年12月14日 Posted by PURGE

Windows上で開発していたアプリを CentOSのサーバへデプロイしたつもりが動作しない。
アクセスすると、ブラウザ上にはエラーメッセージのみ。

仕方ないので、アプリ名/app/log/production.log を覗いてみる。
すると、下記エラー。

ActionView::Template::Error (application.css isn't precompiled):
    2: <html>
    3: <head>
    4:   <title>Sample</title>
    5:   <%= stylesheet_link_tag    "application" %>
    6:   <%= javascript_include_tag "application" %>
    7:   <%= csrf_meta_tags %>
    8: </head>
  app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_ht
ml_erb___1252071779987018877_138162240'

どうやら、テンプレートがプリコンパイルされてないらしい。

で、下記のコマンド。

# rake assets:precompile
(in /app/sample)
/usr/local/ruby1.9/bin/ruby /usr/local/ruby1.9/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
(in /app/sample)
/usr/local/ruby1.9/bin/ruby /usr/local/ruby1.9/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
(in /app/sample)

動作した。

Twitter::ForbiddenError

2011年12月9日 Posted by PURGE

デバッグしながら開発してたら、突然のエラー。 Twitter::ForbiddenError

どうやら更新のレートリミットに引っかかったようだ。

Twitter::ForbiddenError

寝るとしよう。