カテゴリー
Mac

OS X Server 3.1 の caldavd

OS X Server のバージョンアップをしたら例によって caldavd が動かなくなりました。もうお約束過ぎて突っ込む気にもなれませんが、直したのでメモ。書くのをサボってるうちに大分時間が過ぎてしまった…。

といっても、いつものように(?) caldavd 用の PostgreSQL が動いてないだけっぽいですが。

以前バックアップを取るようにしたときにいろいろ調べたので、それをベースに、と思ったらそもそもバックアップも失敗していたのですが(笑)、調査するには役立ちました。

まずはバックアップに失敗してる理由を探れ、ということでスクリプトを一行ずつ実行したところ

caldav_datadir=`ls -d /var/run/caldavd/*/`

でコケているみたい。 3 の時はソケットが /var/run/caldavd/ccs_postgres_XXXXXXXXXXXXXXXXXXXXXX/ という感じで開かれてたので、それに対応すべくこんなコードにしてたんだけどな、とか思いながら /var/run/caldavd を覗いてみると /var/run/caldavd/PostgresSocket/ というのが生えてました。タイムスタンプ的にこっちに移行したようです。なのでここを指定すべく

goro@flora:~$ sudo /Applications/Server.app/Contents/ServerRoot/usr/bin/psql -U _calendar -h /var/run/caldavd/PostgresSocket/ caldav

とかやると PostgreSQL にアクセスできました。となるとバージョンアップに失敗したのカナ? と /var/log/caldavd/migration.log を眺めてみると

2014-03-18 19:03:03+0900 Beginning database schema check.
2014-03-18 19:03:03+0900 Required database key VERSION: 28.
2014-03-18 19:03:03+0900 Actual database key VERSION: 24.
2014-03-18 19:03:03+0900 Starting schema upgrade from version 24 to 28.
2014-03-18 19:03:03+0900 Applying schema upgrade: upgrade_from_24_to_25.sql
2014-03-18 19:03:03+0900 Applying schema upgrade: upgrade_from_25_to_26.sql
2014-03-18 19:03:04+0900 Applying schema upgrade: upgrade_from_26_to_27.sql
2014-03-18 19:03:04+0900 Unable to format event {'log_namespace': 'twext.enterprise.adbapi2', 'log_level': <LogLevel=error>, 'logLevel': 40, 'message': (), 'time': 1395136984.306081, 'log_source': None, 'system': '-', 'why': 'Exception from execute() on first statement in transaction.  Possibly caused by a database server restart.  Automatically reconnecting now.', 'failure': <twisted.python.failure.Failure <class 'pg.ProgrammingError'>>, 'log_logger': <Logger 'twext.enterprise.adbapi2'>, 'log_format': None, 'log_time': 1395136984.305996, 'isError': 1}:
No log format provided
2014-03-18 19:03:04+0900 Step failure
2014-03-18 19:03:04+0900 Step failure
2014-03-18 19:03:04+0900 Step failure
2014-03-18 19:03:04+0900 Step failure
2014-03-18 19:03:04+0900 Step failure
2014-03-18 19:03:04+0900 Step failure
Failed to start service.
2014-03-18 19:03:06+0900 postgres process ended with status 0

これでもか、と言わんばかりに失敗してますね(失笑。であれば再度手動で試せばいいのかな、と upgrade_from_26_to_27.sql を探します。

goro@flora:~$ mdfind upgrade_from_26_to_27.sql
goro@flora:~$

…見つからない。けど、きっと /Applications/Server.app の下にあるには間違いない

goro@flora:~$ find /Applications/Server.app -name upgrade_from_26_to_27.sql
/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_26_to_27.sql
/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_26_to_27.sql
goro@flora:$

ほら、見つかった。 oracle の文言に若干ビビるものの、対象は PostgreSQL だしー、ということで

goro@flora:~$ sudo /Applications/Server.app/Contents/ServerRoot/usr/bin/psql -U _calendar -h /var/run/caldavd/PostgresSocket/ caldav < /Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_26_to_27.sql
goro@flora:$ sudo /Applications/Server.app/Contents/ServerRoot/usr/bin/psql -U _calendar -h /var/run/caldavd/PostgresSocket/ caldav < /Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_27_to_28.sql

…あっさり成功したし。

goro@flora:~$ sudo /Applications/Server.app/Contents/ServerRoot/usr/bin/psql -U _calendar -h /var/run/caldavd/PostgresSocket/ caldav
Password:
psql (9.2.4)
Type "help" for help.

caldav=# select * from CALENDARSERVER WHERE name='VERSION'; 
  name   | value
---------+-------
 VERSION | 28
(1 row)

caldav=#

問題ないっぽいし。

goro@flora:~$ sudo /Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin start calendar
calendar:readWriteSettingsVersion = 1
calendar:setStateVersion = 1
calendar:state = "RUNNING"
calendar:contactsState = "RUNNING"
calendar:calendarState = "RUNNING"
goro@flora:~$

むしろどこで失敗したか問い詰めたくなるレベル(笑)。

ということで再び無事にカレンダーが動くようになりました。

コメントを残す