linux postgre服务名,linux中service配置之postgresql

在Mandriva 2010.2中,安装了postgresql之后,一般很少能直接在/etc/init.d/下生成postgresql的service 文档,这样,就不能在chkconfig中配置postgresql.以下即是postgresql的配置文档,copy后,可以touch一个postgresql,然后贴进去,稍作修改即可。

#section 1

#! /bin/sh

# postgresql    This is the init script for starting up the PostgreSQL

#               server

#

# chkconfig: 2345 85 15

# description: Starts and stops the PostgreSQL backend daemon that handles \

#              all database requests.

# processname: postmaster

# pidfile: /var/run/postmaster.pid

### BEGIN INIT INFO

# Provides: postgresql

# Required-Start: $local_fs $syslog

# Required-Stop:

# Default-Start: 3 4 5

# Default-Stop: 0 1 2 6

# Short-Description: PostgreSql server database

# Description: Starts and stops the PostgreSQL backend daemon that handles

#              all database requests.

### END INIT INFO

# Source function library.

INITD=/etc/rc.d/init.d

. $INITD/functions

# Get function listing for cross-distribution logic.

TYPESET=`typeset -F`

# Get config.

. /etc/sysconfig/network

# Find the name of the script

NAME=postgresql

#section 2

#section 2

# Set defaults for port and database directory

LOGFILE=/var/log/pgsql/postgresql

[ -f /etc/sysconfig/postgresql ] && . /etc/sysconfig/postgresql

[ -f ~postgres/.profile ] && . ~postgres/.profile

# Override defaults from /etc/sysconfig/pgsql if file is present

PGDATA=/usr/local/pgsql/data

export PGDATA

# Check that networking is up.

# Pretty much need it for postmaster.

[ "${NETWORKING}" = "no" ] && exit 0

#[ -f /usr/bin/postmaster ] || exit 0

[ -f /usr/local/pgsql/bin/postmaster ] || exit 0

start(){

PSQL_START=$"Starting ${NAME} service: "

# Check for the PGDATA structure

if [ ! -f $PGDATA/PG_VERSION ]

then

gprintf "Initializing database: "

if [ ! -d $PGDATA ]

then

mkdir -p $PGDATA

chown postgres.postgres $PGDATA

chmod go-rwx $PGDATA

fi

#section 3

#section 3

# Initialize the database

#su -l postgres -s /bin/sh -c "/usr/bin/initdb --pgdata=$PGDATA > /var/log/postgres/postgresql 2>&1" < /dev/null

su -l postgres -s /bin/sh -c "/usr/local/pgsql/bin/initdb --pgdata=$PGDATA > /var/log/postgres/postgresql 2>&1" < /dev/null

[ -f $PGDATA/PG_VERSION ] && echo_success

[ ! -f $PGDATA/PG_VERSION ] && echo_failure

echo

fi

# Check for postmaster already running...

# note that pg_ctl only looks at the data structures in PGDATA

# you really do need the pidof()

#pid=`pidof -s /usr/bin/postmaster`

#if [ $pid ] && /usr/bin/pg_ctl -l ${LOGFILE} status -D $PGDATA > /dev/null 2>&1

pid=`pidof -s /usr/local/pgsql/bin/postmaster`

if [ $pid ] && /usr/local/pgsql/bin/pg_ctl -l ${LOGFILE} status -D $PGDATA > /dev/null 2>&1

then

gprintf "Postmaster already running.\n"

else

#all systems go -- remove any stale lock files

rm -f /tmp/.s.PGSQL.* > /dev/null

gprintf "%s" "$PSQL_START"

#su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl -l ${LOGFILE} -D $PGDATA -p /usr/bin/postmaster start  > /dev/null 2>&1" < /dev/null

su -l postgres -s /bin/sh -c "/usr/local/pgsql/bin/pg_ctl -l ${LOGFILE} -D $PGDATA -p /usr/local/pgsql/bin/postmaster start  > /dev/null 2>&1" < /dev/null

sleep 1

#pid=`pidof -s /usr/bin/postmaster`

pid=`pidof -s /usr/local/pgsql/bin/postmaster`

#secton 4

#secton 4

if [ $pid ]

then

if echo "$TYPESET"|grep "declare -f success" >/dev/null

then

success "%s" "$PSQL_START"

else

gprintf "  [ OK ]\n"

fi

touch /var/lock/subsys/${NAME}

echo $pid > /var/run/postmaster.pid

echo

else

if echo "$TYPESET"|grep "declare -f failure" >/dev/null

then

failure "%s" "$PSQL_START"

else

gprintf " [ FAILED ]\n"

fi

echo

fi

fi

}

stop(){

PSQL_STOP=$"Stopping ${NAME} service: "

gprintf "%s" "$PSQL_STOP"

#su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl -l ${LOGFILE} stop -D $PGDATA -s -m fast" > /dev/null 2>&1

su -l postgres -s /bin/sh -c "/usr/local/pgsql/bin/pg_ctl -l ${LOGFILE} stop -D $PGDATA -s -m fast" > /dev/null 2>&1

ret=$?

if [ $ret -eq 0 ]

then

#section 5

#section 5

if echo "$TYPESET"|grep "declare -f success" >/dev/null

then

success "%s" "$PSQL_STOP"

else

gprintf "  [ OK ]\n"

fi

else

if echo "$TYPESET"|grep "declare -f failure" >/dev/null

then

failure "%s" "$PSQL_STOP"

else

gprintf "  [ FAILED ]\n"

fi

fi

echo

rm -f /var/run/postmaster.pid

rm -f /var/lock/subsys/${NAME}

}

restart(){

stop

start

}

condrestart(){

[ -e /var/lock/subsys/${NAME} ] && restart

}

#section 6

#section 6

reload(){

#su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl -l ${LOGFILE} reload -D $PGDATA -s" > /dev/null 2>&1

su -l postgres -s /bin/sh -c "/usr/local/pgsql/bin/pg_ctl -l ${LOGFILE} reload -D $PGDATA -s" > /dev/null 2>&1

}

# This script is slightly unusual in that the name of the daemon (postmaster)

# is not the same as the name of the subsystem (postgresql)

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

status)

status postmaster

;;

restart)

restart

;;

condrestart)

condrestart

;;

reload|force-reload)

reload

;;

*)

gprintf "Usage: %s {start|stop|status|restart|condrestart|reload|force-reload}\n" "$0"

exit 1

esac

#section 7

exit 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值