Skip to main content

make sure pgpool node/instance is up ( with bash script )

--idea--
this idea came to me when some one ask " how do we ensure that postgresql's node has been activated again ? ". by asking google and with have no answer, finally why we don't make a happy script with bash ^_^...

--scenario--
as simple as i love to, this script is run as background service that check node's status every 3 second. And if one of node/both is down, script is automatic bring it UP/ON again.

--1--
must to know  how to chek node status:
*> node UP/ON
$ tail /var/log/pgpool.log
2011-12-22 10:06:18 DEBUG: pid 8726: starting health checking
2011-12-22 10:06:18 DEBUG: pid 8726: health_check: 0 th DB node status: 1
2011-12-22 10:06:18 DEBUG: pid 8726: health_check: 1 th DB node status: 1

$ pcp_node_info 10 localhost 9898 postgres password 1
xxx.xxx.xxx.xxx. xxxx 1 1073741823.500000
$ pcp_node_info 10 localhost 9898 postgres password 1 | awk '{print $3}'
1

*> node Down
$ tail /var/log/pgpool.log
2011-12-22 10:14:41 DEBUG: pid 8726: starting health checking
2011-12-22 10:14:41 DEBUG: pid 8726: health_check: 0 th DB node status: 1
2011-12-22 10:14:41 DEBUG: pid 8726: health_check: 1 th DB node status: 3

$ pcp_node_info 10 localhost 9898 postgres password 1
10.10.130.17 5432 3 1073741823.500000
$ pcp_node_info 10 localhost 9898 postgres password 1 | awk '{print $3}'
3

--script--

#!/bin/bash
# brekele.inc

Node_stat=`pcp_node_info 10 localhost 9898 postgres password 0 | awk '{print $3}'`
Node_stat2=`pcp_node_info 10 localhost 9898 postgres password 1 | awk '{print $3}'`

echo "PID: $$ : `date` : daemon check \" $0 \" is running"
echo "=========== Hit Ctl-C to exit ============"

start(){
#echo "jalankan"
pcp_attach_node  90 localhost 9898 postgres password 0 && echo "node UP" || echo "node Down"
}

start2(){
#echo "jalankan"
pcp_attach_node  90 localhost 9898 postgres password 1 && echo "node UP" || echo "node Down"
}

if [ $Node_stat -eq 3 ]
then
start
fi

if [ $Node_stat2 -eq 3 ]
then
start2
fi

sleep 3
exec $0

echo "This line will never echo!"
exit 99

--cek & jajal--
try run on your own terminal/console and with your awn risk ^_^
$ ./script
PID: 26284 : Thu Dec 22 10:43:06 WIT 2011 : daemon check " /mnt/script " is running
=========== Hit Ctl-C to exit ============
PID: 26284 : Thu Dec 22 10:43:09 WIT 2011 : daemon check " /mnt/script " is running
=========== Hit Ctl-C to exit ============



Comments

Post a Comment

comment please ...

Popular posts from this blog

Webalizer - Statistik trafik/kunjungan web (ubuntu)

--goal--
make subdomain trafik statistik

--install--
run this command :
sudo apt-get install webalizeredit "/etc/apache2/apache2.conf" , set
HostnameLookups Off into :
HostnameLookups On
--1--
All we need is already prepared, now set log of vhost in "/etc/apache2/sites-enabled" to spesifict folder.
exp. $sudo vi /etc/apache2/sites-enabled/monitor CustomLog ${APACHE_LOG_DIR}/access.log into: CustomLog ${APACHE_LOG_DIR}/vhost/monitor/access.logrestart service
$sudo /etc/init.d/apache2 restart
--2--
create another file config of webalizer in /etc/webalizer
exp. vi /etc/webalier/monitor.conf
set the LogFile to apache2 logfile:
LogFile /var/log/apache2/vhost/monitor/access.log # apache log OutputDir /var/webalizer/monitor/ #webalizer report Incremental yes ReportTitle Usage statistics for HostName monitor.brekele.co.cc
--3--
create script to run webalizer via crontab
exp. vi /etc/webalizer/cron_job
#!/bin/bash echo "di jalankan pada: `date +"%d-%B-%Y %r"…

pgpoolAdmin, web interface for pgpool

--preparation--
next capter of pgpool from my last post ( here), now i wanna post about a tool that can manage pgpool from web interface called pgpoolAdmin. next... enjoy the post... ^_^

--1--
first we need to download pgpooladmin from here, extrak and copy or move to http directory( for exp : /var/www) 
$wget http://pgfoundry.org/frs/download.php/2964/pgpoolAdmin-3.0.3.tar.gz $tar zxvf pgpoolAdmin-3.0.3.tar.gz $sudo cp -Rf pgpoolAdmin-3.0.3 /var/www/test
 --2--
install pgpooladmin via web on: http://localhost/test/install


make sure owner of that file is "www-data"(of course have write akses) and check again



login with user that you create on /etc/pcp.conf (for more detail see my last post



and done.ya.. tooo.......!!!
 ^_^

send oracle 11g audit log to syslog server ( on other PC)

--preparation-- 
well...... this time i will write about syslog, and for this experiment what we need is :
- kiwi syslog server get from here and install it on your PC( i use xp for this server syslog)
- oracle db
- and of course, a cup of coffee is a must and other thing that make you relax and comfortable ( :p )

--scema--
first thing to do is redirect oracle audit log to syslog, and than from syslog send to syslog server( kiwi syslog)

--1--
 edit initSID.ora and add this folowing config :
create "/var/log/oracle/" firs
audit_file_dest='/var/log/oracle/' audit_trail='OS' AUDIT_SYSLOG_LEVEL=local1.warning after that edit /etc/syslog.conf, and add this folowing config :
#Save oracle rdbms audit trail to oracle_audit.log local1.warning /var/log/oracle/oracle_audit.log #Send oracle rdbms audit trail to remote syslog server local1.warning @1.1.1.1 #<= ip your syslog server--2--
restart syslog service with command :
/sbin/service syslog restart …