2010年10月28日木曜日

svnで特定のファイル(やディレクトリ)を除外して管理する

どうも、俺@お昼ごはんでお腹いっぱいです。

今日はsvnコマンドで特定のファイルやディレクトリを除外する方法についてメモメモ。

例えば、
リポジトリ管理下の tmp/ というディレクトリを除外する場合。
$ svn propset svn:ignore /path/to/tmp
// または
$ svn propedit svn:ignore // ここでリターン
// SVN_EDITORで指定したエディタが開くので除外パターンを改行区切りで記述
/path/to/tmp
こんな感じです。

logsディレクトリ以下の*.logというファイルを除外する場合は
$ svn propset svn:ignore '*.log' /path/to/logs
// または
$ svn propedit svn:ignore /path/to/logs
// SVN_EDITORで指定したエディタが開くので除外パターンを改行区切りで記述
*.log
こんな感じです。


propsetはそのコマンドでパターンを指定する方法で
propeditは設定ファイルでパターンを指定する方法です。

以上でぇぇす。

2010年10月22日金曜日

svnでどんなに頑張っても"can't convert string from 'utf-8' to native encoding"エラーが治らない

どうも、俺@残業です。

svnコマンドでimport chekcout commit updateコマンドを打った時によく出るエラーで
Can't convert string from native encoding to 'UTF-8':
Valid UTF-8 data.
ネイティブのエンコーディングから'UTF-8'に文字列を変換できません
有効なUTF-8のデータ(16進数: )の後に無効なUTF-8文字列(16進数)
のようなエラーがあります。

だいたいの原因が、存在するファイルに日本語ファイル名のものがある場合に発生する事があるのですが、おそらくlinuxエンジニアはやらないのでwindowsで誰かが作ったファイルが存在していることだと思います。

大抵の場合は環境変数 LC_CTYPE= の設定で対応できます。
$ export LC_CTYPE=ja_JP.utf8


ja_JP.utf8なロケールが存在しない場合は(まずないと思いますが)
locale -a | grep ja
ja_JP
ja_JP.eucjp
ja_JP.sjis
ja_JP.ujis
japanese
japanese.euc
入れちゃいましょう。
# localedef -f UTF-8 -i ja_JP ja_JP.utf8


それでも同じエラーが出る場合は
$ export LC_ALL=ja_JP.utf8
やっちゃいましょう。

それでもエラーが出る場合は思い切って
$ export LC_CTYPE=ja_JP.sjis
をやってみてください。
ja_JP.sjisなロケールがない場合は
# localedef -f SJIS -i ja_JP ja_JP.sjis
で追加してください。

LC_CTYPE=ja_JP.sjisでやれば回避できることもあります。

最後の手段は
$ vim ~/.subversion/config
log-encoding=utf8
です。

これでもダメなら日本語ファイル名のファイルをsvn管理下から外してください!


以上どぇぇぇぇぇぇす。

2010年10月20日水曜日

mysql + senna インストール

どうも、僕です。

MySQL+sennaで全文検索対応させるためインストールした時にトラブったのでメモ。
あ、原因はわからないままなのですが、、、
環境はKVM上でのCentOS5.5です。(KVMはLDAP認証でそれが怪しいと思っているのですが、、)


まずmecabをインスコ。(今回はmecab-0.98.tar.gz/mecab-ipadic-2.7.9-20070801.tar.gz)
http://sourceforge.net/project/showfiles.php?group_id=177856からmecab(本体)とmecab-ipadic(辞書)を落としてきます。
mecabは
# ./configure --prefix=/usr --with-charset=utf8
でmecab-ipadicは
# ./configure --prefix=/usr --with-charset=utf8
でmake & make install します。

同様にsennaも(今回はsenna-1.1.5.tar.gz)
http://sourceforge.jp/projects/senna/files/からソースを落としてきて
# ./configure --prefix=/usr
でインスコします。

最後にtrittonを(今回はtritonn-1.0.12-mysql-5.0.87.tar.gz)
http://sourceforge.jp/projects/tritonn/releases/からソースGETし
# ./configure  --prefix=/usr/local/mysql --with-charset=sjis --with-extra-charsets=complex --with-mysql-user=mysql --without-bench --enable-assembler --with-mysqld-ldflags=-all-static --without-docs --with-senna --with-mecab CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro -felide-constructors -fno-exceptions -fno-rtti"
でインストールしました。

ここから通常のmysqlインストールと同じ作業を行います。
# groupadd mysql
# useradd -d /usr/local/mysql -g mysql mysql
# chown -R mysql:mysql /usr/local/mysql
# /usr/local/mysql/bin/mysql_install_db --user=mysql
ここでコケました。
内容は
   1 101019 20:51:13  mysqld started
2 101019 20:51:13 - mysqld got signal 11 ;
3 This could be because you hit a bug. It is also possible that this binary
4 or one of the libraries it was linked against is corrupt, improperly built,
5 or misconfigured. This error can also be caused by malfunctioning hardware.
6 We will try our best to scrape up some info that will hopefully help diagnose
7 the problem, but since we have already crashed, something is definitely wrong
8 and this may fail.
9
10 key_buffer_size=0
11 read_buffer_size=262144
12 max_used_connections=0
13 max_connections=100
14 threads_connected=0
15 It is possible that mysqld could use up to
16 key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 76800 K
17 bytes of memory
18 Hope that's ok; if not, decrease some variables in the equation.
19
20 thd=(nil)
21 Attempting backtrace. You can use the following information to find out
22 where mysqld died. If you see no messages after this, something went
23 terribly wrong...
24 Cannot determine thread, fp=0xbf908e38, backtrace may not be correct.
25 Stack range sanity check OK, backtrace follows:
26 0x80eab85
27 0x85fdd5
28 0x854f70
29 0x856cc0
30 0x85e67d0 31 0x85e69b6
32 0x80e9bef
33 0x80ef2f0
34 0x85a2398
35 0x8048131
36 New value of fp=(nil) failed sanity check, terminating stack trace!
37 Please read http://dev.mysql.com/doc/mysql/en/using-stack-trace.html and follow instructions on how to resolve the stack trace. Resolved
38 stack trace is much more helpful in diagnosing the problem, so please do
39 resolve it
40 The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
41 information that should help you find out what is causing the crash.
42
43 This crash occured while the server was calling initgroups(). This is
44 often due to the use of a mysqld that is statically linked against glibc
45 and configured to use LDAP in /etc/nsswitch.conf. You will need to either
46 upgrade to a version of glibc that does not have this problem (2.3.4 or
47 later when used with nscd), disable LDAP in your nsswitch.conf, or use a
48 mysqld that is not statically linked.
49 101019 20:51:13 mysqld ended
といったもの。
/etc/my.cnfを作ってメモリ少なくして実行してもダメ、出力されたログをトレースしても意味不明。「何かがクラッシュしたぜ」としか出てこない。
気になるのは最後の文章
  43 This crash occured while the server was calling initgroups(). This is
44 often due to the use of a mysqld that is statically linked against glibc
45 and configured to use LDAP in /etc/nsswitch.conf. You will need to either
46 upgrade to a version of glibc that does not have this problem (2.3.4 or
47 later when used with nscd), disable LDAP in your nsswitch.conf, or use a
48 mysqld that is not statically linked.
なにやらLDAPを使わないようにしてみたら?的なアドバイスが出る。
ただしサーバ管理者は俺じゃないのであきらめる、、、。



とりあえず解決方法は、mysqlユーザになってやる!です。
# su mysql -
$ /usr/local/mysql/bin/mysql_install_db
これで難なくできちゃいました。
またその後mysqlデーモンをrootで立ち上げようとすると
# service mysql start
Starting MySQL.Manager of pid-file quit without updating file [失敗]
とか出ちゃう。
# /usr/local/mysql/bin/mysqld_safe &
Starting mysqld daemon with databases from /usr/local/mysql/var
STOPPING server from pid file /usr/local/mysql/var/xxxxx.mysql.pid
101020 10:45:20 mysqld ended

[1] +done ./bin/mysqld_safe
となぜか起動しない。
起動スクリプトなど確認したが、そのスクリプトがうまく解読できない、、、。ソース読んでると意味不明の実装がされてたりするし、、

これも
# service mysql start --user=root
または
# /usr/local/mysql/bin/mysqld_safe --user=root &
とやると起動できる。



sennaのバグなのか、KVM上でのOSの問題なのか、LDAP認証の問題なのか引き続き調査しまぁぁぁぁぁす。

2010年10月15日金曜日

jqueryでチェックボックスの状態を取得する

どうも、俺@お昼前です。

jqueryでcheckboxの状態(チェックされているかどうか)を取得する方法めもです。
$("#foo_checkbox").attr("checked");
// または
$("#foo_checkbox").is(":checked");


ちなみに、チェックボックスにチェックを入れる場合は
$("#foo_checkbox").attr("checked", "checked");


チェックボックスのチェックを外すには
$("#foo_checkbox").attr("checked", "");



以上でぇぇぇえぇっぇえぇす。