반응형

/****************************************************************************************************************
-- Title : [9.2] How to register postgresql service and auto start when server boots up
-- Key word : chkconfig postgresql auto start 자동시작 자동 시작 서비스 등록
****************************************************************************************************************/


1. Move directory
    # cd /etc/init.d
 
2. Generate service script as typed below:
    # vi postgresql
 
    <BOF>
    #!/bin/bash
 
    # chkconfig:2345 90 20
    
    # PostgreSQL START/STOP Script
    SERVER=/home/postgres/pgsql/bin/postmaster
    PGCTL=/home/postgres/pgsql/bin/pg_ctl
    PGDATA=/home/postgres/pgsql/data
    OPTIONS=-i
    LOGFILE=/home/postgres/pgsql/data/postmaster.log
    
    case "$1" in
        start)
            echo -e "!!! Starting PostgreSQL...... "
            su -l postgres -c "nohup $SERVER $OPTIONS -D $PGDATA >> $LOGFILE 2>&1 &"
            ;;
        stop)
            echo -e "!!! Stopping PostgreSQL...... "
            su -l postgres -c "$PGCTL -D $PGDATA stop"
            ;;
        restart)
            echo -e "!!! Restarting PostgreSQL...... "
            su -l postgres -c "$PGCTL -D $PGDATA restart"
            ;;
        status)
            echo -e "!!! Status PostgreSQL...... "
            su -l postgres -c "$PGCTL status"
            ;;
        *)
            echo "Usage: $0 {start|stop|restart|status}"
            exit 1
            ;;
    esac
    
    exit 0
    <EOF>
 
3. Allow privilege to script
    # chmod 755 postgresql
 
4. Register postgresql service
    # chkconfg --add postgresql
    
5. Confirm registration
    # chkconfig --list postgresql
 
6. Test(should do by root)
    # service postgresql start
    # service postgresql stop
    # service postgresql status
    # service postgresql start
    # service postgresql restart
 
7. Check reboot and auto start
    # reboot -r now
      ....
    # service postgresql status

8. Delete service
    # chkconfig --del postgresql

 

반응형

+ Recent posts