ます’s Blog - どうでもいい記事100選

どうでもいい記事100選

postmaster.pid

最近、開発環境がすっ飛ぶ事が多くて困ってます。
復旧(OSを起動)させる度にpidファイルを消すのがうっとうしい。。。基本、ソースからインストール派。
最初は我慢していたのですが(段々と頻度が多くなってきたので)そろそろ本格的に対応を行おうかと。
ちょっと強引ですが、pidファイルの生成場所を「/tmp」の下にしてしまおうと考えました。
これなら開発環境がすっ飛んでも復旧(OSを起動)すれば即起動、みたいな。
ターゲットはApacheが4つとMySQLPostgreSQL
Apacheについては「httpd.conf」の「PidFile」項目と起動スクリプト(/bin/apachectlを流用)の「PIDFILE」項目を変更する事で完了。
MySQLについては起動スクリプト(/share/mysql/mysql.serverを流用)の「pid_file」項目を変更する事で完了。
で、PostgreSQLは。。。。設定する項目が無い。駄目じゃん。_| ̄|○
起動スクリプトや設定ファイルの中にも見当たらなかったので、ソースをgrepしてみる。

% ./TAKO.php 'postmaster.pid'  postgresql-7.3.18 3
postgresql-7.3.18/src/bin/pg_resetxlog/pg_resetxlog.c
209:    snprintf(path, MAXPGPATH, "%s/postmaster.pid", DataDir);
postgresql-7.3.18/src/backend/utils/init/miscinit.c
650: * ($DATADIR/postmaster.pid) and a Unix-socket-file lockfile ($SOCKFILE.lock).
854:    snprintf(lockfile, sizeof(lockfile), "%s/postmaster.pid", datadir);


% ./TAKO.php 'postmaster.pid'  postgresql-7.4.16 3
postgresql-7.4.16/src/bin/pg_resetxlog/pg_resetxlog.c
207:    snprintf(path, MAXPGPATH, "%s/postmaster.pid", DataDir);
postgresql-7.4.16/src/backend/utils/init/miscinit.c
418: * ($DATADIR/postmaster.pid) and a Unix-socket-file lockfile ($SOCKFILE.lock).
639:    snprintf(lockfile, sizeof(lockfile), "%s/postmaster.pid", datadir);


% ./TAKO.php 'postmaster.pid'  postgresql-8.0.12 3
postgresql-8.0.12/src/bin/pg_ctl/pg_ctl.c
1525:           snprintf(pid_file, MAXPGPATH, "%s/postmaster.pid", pg_data);
postgresql-8.0.12/src/bin/pg_resetxlog/pg_resetxlog.c
216:    snprintf(path, MAXPGPATH, "%s/postmaster.pid", DataDir);
postgresql-8.0.12/src/backend/postmaster/postmaster.c
615:     * (Put any slow processing further down, after postmaster.pid creation.)
681:     * postmaster.pid file.  This prevents problems with boot scripts that
postgresql-8.0.12/src/backend/postmaster/syslogger.c
13: * creation time and current postmaster pid.
postgresql-8.0.12/src/backend/utils/init/miscinit.c
443: * ($DATADIR/postmaster.pid) and a Unix-socket-file lockfile ($SOCKFILE.lock).
714:    snprintf(lockfile, sizeof(lockfile), "%s/postmaster.pid", datadir);
postgresql-8.0.12/src/backend/utils/misc/guc.c
1853:            gettext_noop("Writes the postmaster PID to the specified file."),


% php ./TAKO.php 'postmaster.pid'  postgresql-8.1.8 3
postgresql-8.1.8/src/bin/pg_ctl/pg_ctl.c
1528:           snprintf(pid_file, MAXPGPATH, "%s/postmaster.pid", pg_data);
postgresql-8.1.8/src/bin/pg_resetxlog/pg_resetxlog.c
248:    snprintf(path, MAXPGPATH, "%s/postmaster.pid", DataDir);
postgresql-8.1.8/src/backend/postmaster/postmaster.c
628:     * (Put any slow processing further down, after postmaster.pid creation.)
686:     * postmaster.pid file.  This prevents problems with boot scripts that
postgresql-8.1.8/src/backend/postmaster/syslogger.c
13: * creation time and current postmaster pid.
postgresql-8.1.8/src/backend/utils/init/miscinit.c
47:#define DIRECTORY_LOCK_FILE          "postmaster.pid"
632: * ($DATADIR/postmaster.pid) and a Unix-socket-file lockfile ($SOCKFILE.lock).
postgresql-8.1.8/src/backend/utils/misc/guc.c
2118:                   gettext_noop("Writes the postmaster PID to the specified file."),


% php ./TAKO.php 'postmaster.pid'  postgresql-8.2.3 3
postgresql-8.2.3/src/bin/pg_ctl/pg_ctl.c
1743:           snprintf(pid_file, MAXPGPATH, "%s/postmaster.pid", pg_data);
postgresql-8.2.3/src/bin/pg_resetxlog/pg_resetxlog.c
262:    snprintf(path, MAXPGPATH, "%s/postmaster.pid", DataDir);
postgresql-8.2.3/src/backend/postmaster/postmaster.c
645:     * (Put any slow processing further down, after postmaster.pid creation.)
703:     * postmaster.pid file.  This prevents problems with boot scripts that
postgresql-8.2.3/src/backend/postmaster/syslogger.c
13: * creation time and current postmaster pid.
postgresql-8.2.3/src/backend/utils/init/miscinit.c
45:#define DIRECTORY_LOCK_FILE          "postmaster.pid"
610: * ($DATADIR/postmaster.pid) and a Unix-socket-file lockfile ($SOCKFILE.lock).
postgresql-8.2.3/src/backend/utils/misc/guc.c
2261:                   gettext_noop("Writes the postmaster PID to the specified file."),
postgresql-8.2.3/src/test/regress/pg_regress.c
102:static PID_TYPE postmaster_pid = INVALID_PID;
1523:           postmaster_pid = spawn_process(buf);
1524:           if (postmaster_pid == INVALID_PID)
1549:                   if (kill(postmaster_pid, 0) != 0)
1551:                   if (WaitForSingleObject(postmaster_pid, 0) == WAIT_OBJECT_0)
1571:                   if (kill(postmaster_pid, SIGKILL) != 0 &&
1576:                   if (TerminateProcess(postmaster_pid, 255) == 0)
1587:                      temp_port, (unsigned long) postmaster_pid);

「$PGDATA/postmaster.pid」固定っぽい。。。ふーん。って、駄目じゃん。_| ̄|○
流石に「$PGDATA」を「/tmp」に置くのは出来ないか。。。固定にしておく気持ちは分からんでもないが。
pidファイルの生成場所を指定するパラメータを追加してみたかったけど(余裕が無いので)こんな感じで逃げ。ヘタレっぷりが凄い。

--- postgresql-7.4.16,orig/src/bin/pg_resetxlog/pg_resetxlog.c	2003-09-07 12:43:53.000000000 +0900
+++ postgresql-7.4.16/src/bin/pg_resetxlog/pg_resetxlog.c	2007-02-21 22:35:02.371977742 +0900
@@ -204,7 +204,7 @@
 	 * proceed, on grounds we might be interfering with a live
 	 * installation.
 	 */
-	snprintf(path, MAXPGPATH, "%s/postmaster.pid", DataDir);
+	snprintf(path, MAXPGPATH, "/tmp/postmaster.pid");
 
 	if ((fd = open(path, O_RDONLY)) < 0)
 	{
--- postgresql-7.4.16,orig/src/backend/utils/init/miscinit.c	2003-09-27 00:27:37.000000000 +0900
+++ postgresql-7.4.16/src/backend/utils/init/miscinit.c	2007-02-21 22:35:37.478166471 +0900
@@ -636,7 +636,7 @@
 {
 	char		lockfile[MAXPGPATH];
 
-	snprintf(lockfile, sizeof(lockfile), "%s/postmaster.pid", datadir);
+	snprintf(lockfile, sizeof(lockfile), "/tmp/postmaster.pid");
 	CreateLockFile(lockfile, amPostmaster, true, datadir);
 	/* Save name of lockfile for RecordSharedMemoryInLockFile */
 	strcpy(directoryLockFile, lockfile);

これを適用した上で再インストール。
でもって「$PGDATA/bin/pg_ctl」の「PIDFILE」項目を変更する事で完了。やれやれ。
OS起動時に、pidファイルを検知して削除するシェル・スクリプトを新しく書けばよいだけの気もするが。
ディストリビューションのパッケージなんかは、そうなってるのかなぁ。一度も使った事は無いけどそんな気がする。