postgres solaris smf服务可以在线监听状态,然后才能监听连接

我有一个SMF服务(Naviserver Web服务器),它依赖于Postgre的启动和运行(即接受连接)。 Postgres在它实际上能够接受任何连接之前报告它的状态为“在线”。 这会导致Web服务器无法正常启动。 据我所知,一旦postgres启动方法被调用,SMF就会在线报告,而不是等待postgres表明已经准备好的某种状态。

SMF清单:

<?xml version=1.0?> <!DOCTYPE service_bundle SYSTEM /usr/share/lib/xml/dtd/service_bundle.dtd.1> <service_bundle type=manifest name=export> <service name=application/database/postgresql_945 type=service version=0> <dependency name=network grouping=require_all restart_on=none type=service> <service_fmri value=svc:/milestone/network:default/> </dependency> <dependency name=filesystem-local grouping=require_all restart_on=none type=service> <service_fmri value=svc:/system/filesystem/local:default/> </dependency> <exec_method name=start type=method exec=/lib/svc/method/postgres_945 start timeout_seconds=60/> <exec_method name=stop type=method exec=/lib/svc/method/postgres_945 stop timeout_seconds=60/> <exec_method name=refresh type=method exec=/lib/svc/method/postgres_945 refresh timeout_seconds=60/> <property_group name=general type=framework> <propval name=action_authorization type=astring value=solaris.smf.manage.postgres/> <propval name=value_authorization type=astring value=solaris.smf.value.postgres/> </property_group> <instance name=default_64bit enabled=true> <method_context> <method_credential group=postgres user=postgres/> </method_context> <property_group name=postgresql_945 type=application> <propval name=bin type=astring value=/usr/postgres/9.4.5/bin/> <propval name=data type=astring value=/var/postgres-94/data/> <propval name=log type=astring value=/var/postgres-94/logs/server.log/> <propval name=value_authorization type=astring value=solaris.smf.value.postgres/> </property_group> </instance> <stability value=Evolving/> <template> <common_name> <loctext xml:lang=C>PostgreSQL RDBMS version postgresql_945</loctext> </common_name> <documentation> <manpage title=postgresql_945 section=5/> <doc_link name=postgresql.org uri=http://postgresql.org/> </documentation> </template> </service> </service_bundle> 

方法文件:

  #!/sbin/sh # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # #ident @(#)postgresql_945 1.1 08/04/30 SMI . /lib/svc/share/smf_include.sh # SMF_FMRI is the name of the target service. This allows multiple instances # to use the same script. getproparg() { val=`svcprop -p $1 $SMF_FMRI` [ -n $val ] && echo $val } check_data_dir() { if [ ! -d $PGDATA ]; then echo Error: postgresql_945/data directory $PGDATA does not exist exit $SMF_EXIT_ERR_CONFIG fi if [ ! -w $PGDATA ]; then echo Error: postgresql_945/data directory $PGDATA is not writable by postgres exit $SMF_EXIT_ERR_CONFIG fi if [ ! -d $PGDATA/base -o ! -d $PGDATA/global -o ! -f $PGDATA/PG_VERSION ]; then # If the directory is empty we can create the database files # on behalf of the user using initdb if [ `ls -a $PGDATA | wc -w` -le 2 ]; then echo Notice: postgresql_945/data directory $PGDATA is empty echo Calling '$PGBIN/initdb -D $PGDATA' to initialize $PGBIN/initdb -D $PGDATA if [ $? -ne 0 ]; then echo Error: initdb failed exit $SMF_EXIT_ERR fi else echo Error: postgresql_945/data directory $PGDATA is not empty, nor is it a valid PostgreSQL data directory exit $SMF_EXIT_ERR_CONFIG fi fi } PGBIN=`getproparg postgresql_945/bin` PGDATA=`getproparg postgresql_945/data` PGLOG=`getproparg postgresql_945/log` if [ -z $SMF_FMRI ]; then echo Error: SMF framework variables are not initialized exit $SMF_EXIT_ERR fi if [ -z $PGDATA ]; then echo Error: postgresql_945/data property not set exit $SMF_EXIT_ERR_CONFIG fi if [ -z $PGLOG ]; then echo Error: postgresql_945/log property not set exit $SMF_EXIT_ERR_CONFIG fi case $1 in start) check_data_dir $PGBIN/pg_ctl -D $PGDATA -l $PGLOG start ;; stop) $PGBIN/pg_ctl -D $PGDATA stop -m fast ;; refresh) $PGBIN/pg_ctl -D $PGDATA reload -m fast ;; *) echo Usage: $0 {start|stop|refresh} exit 1 ;; esac exit $SMF_EXIT_OK 

我能做些什么来确保postgres不会在线报告,直到它接受连接或检查postgres实际上是从我的web服务器启动的。 谢谢!

根据pg_ctl文档 :

概要

pg_ctl start [-w] [-t seconds] [-s] [-D datadir] [-l filename] [-o options] [-p path] [-c]

选项

-w

等待启动或关机完成。 等待是关机的默认选项,但不是初创公司。 在等待启动时​​,pg_ctl反复尝试连接到服务器。 等待关机时,pg_ctl等待服务器删除其PID文件。 pg_ctl根据启动或closures的成功返回一个退出代码。

-W

不要等待启动或关机完成。 这是启动和重启模式的默认值。

例子

启动服务器

要启动服务器,请等待服务器接受连接:

$ pg_ctl -w start

由于$PGBIN/pg_ctl -D $PGDATA -l $PGLOG start命令具有隐式的-W选项,所以在PostgrSQL服务方法文件中的命令中添加-w选项应该做你想做的, 只要你的web服务器服务依赖于PostgreSQL服务

 $PGBIN/pg_ctl -D $PGDATA -l $PGLOG -w start 

只要记得检查文件是否被修改,如果你打补丁/更新服务器。