プロが教える店舗&オフィスのセキュリティ対策術

PostgreSQLをサーバ起動時にstartさせたいと思っています。

/etc/rc.d/rc.localに下記を追記しましたが、起動してくれません。ログファイルも作成されていませんでした。

echo -n "Starting PostgreSQL: "
su -l pgsql -s /bin/sh -c "/usr/local/pgsql/bin/pg_ctl -l /var/log/postgresql.log start > /dev/null 2>&1" < /dev/null
echo "done."

何が悪いのでしょうか?PostgreSQLは手動でstartすることはできます。

また、PostgreSQLの起動スクリプトを作成し、webminで制御したいと思うのですが、PostgreSQLの起動スクリプトの書き方について参考になるHPがあれば紹介していただきたいと思っています。

よろしくお願いいたします。

A 回答 (3件)

起動スクリプトの書き方は、参考URLがいかがでしょう。



僕自身が使っているスクリプトを参考に書いておきます。
アカウント名や、パスの環境変数を書き換えてください。
(RedHat7.3, postgresql7.2.1で使っています。)

chkconfig対応なので、
パーミッションを755か700にして、
chkconfig --add postgres
とすると、起動時に起動してくれます。
chkconfig --list
として確認できます。


#!/bin/sh
#
#
# chkconfig: 35 85 15
# description: Starts and stops the PostgreSQL backend daemon\
# that handles all database requests.
# processname: postmaster
#
# Config Variables
#
PGACCOUNT="postgres"

#
# The non-root user account which will be used to run the
# PostgreSQL executeable. For this script to work, the
# shell for this account must be SH/BASH.
#
export PGDATA="/usr/local/pgsql/data"
export POSTMASTER="/usr/local/pgsql/bin/postmaster -S -i"
export PG_CTL="/usr/local/pgsql/bin/pg_ctl"

#
# The executable program which is to be run, in this case
# it is the listener, which waits for requests on the port
# specified during configuration.
#
# Source function library.
. /etc/rc.d/init.d/functions

#
# See how we were called.
#
case "$1" in
start)
echo -n "Starting postgres: "
su - $PGACCOUNT -c "$POSTMASTER"
echo
touch /var/lock/subsys/postgres
;;
stop)
echo -n "Stopping postgres: "
$PG_CTL -m f stop
echo
rm -f /var/lock/subsys/postgres
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac

exit 0

参考URL:http://www.zdnet.co.jp/help/howto/linux/0007mast …
    • good
    • 0

PostgreSQLをソースからビルドした場合、contrib/start-scriptsにFreeBSDとLinux用の起動スクリプトがありますが、それを利用するのではいけないのでしょうか?



Linuxであれば、
# cp contrib/start-scripts/linux /etc/init.d/postgresql
# chmod +x /etc/init.d/postgresql
# chkconfig --add postgresql
とすればシステムサービスに登録されます。

PGDATAのパスが/usr/local/pgsql/dataでない場合は、スクリプトを集成してやる必要があります。
    • good
    • 0
この回答へのお礼

そんな便利なものがあるとは知りませんでした!
ありがとうございます!!

お礼日時:2002/08/21 19:48

あなたが使われているOSやpostgresの種類やバージョンがいっさい記述されていないので不正確かもしれませんが、



su - pgsql -c "/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data &"

こんな感じでrc.localに記述しています。
(TurboLinux7WS,postgresql7.2.1)

この回答への補足

説明不足でしたm(__)m
RedHat7.3,postgresql7.2.1です。

早速試してみます!

補足日時:2002/08/18 15:07
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!