Chinaunix首页 | 论坛 | 博客
  • 博客访问: 485205
  • 博文数量: 279
  • 博客积分: 4467
  • 博客等级: 上校
  • 技术积分: 2830
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-03 14:43
文章分类

全部博文(279)

文章存档

2013年(1)

2012年(39)

2011年(35)

2009年(29)

2008年(131)

2007年(44)

分类:

2008-06-13 13:31:00

6.       stopwservices.pl
it will require "stop_3306.sh"
implementation:
1. block the port 3306
 2. check transaction status
 3. if all transaction status =1 or 2, then we can shutdown the crond and mysql
 4. if transaction status=0, we will reran the transaction until no status=0
 5 done
Description: stop ws1 services safely, it will stop mysql network connection, then execute all the transaction once until no records status remain checkalltransactionstatus.pl

Implementation:
1. add "skip-networking" to stop network connection of mysql.
2. restart mysql
3. then execute all transaction until no records remain status_flag=0;

return:
1. Done
2. Fail:

#!/usr/bin/perl
require '/opt/ws1/run_control.pl';
system "$ws2/stop_3306.sh";
open FILE,"$ws2/stop_table.txt" or die "can't open file:$!\n";
my $stagedbh=DBI->connect("DBI:mysql:database=$localdatabase;host=$localdbhost","$localdbuser","$localdbpass",{'RaiseError'=>1, 'AutoCommit' => 0}) or die "cannot connect!\n";
foreach $table(<FILE>){
if ($_=~/,/){
@dst_table=split /,/,$table;
foreach(@dst_table){
$sth=$stagedbh->prepare(qq/select status_flag from $_/);
$sth->execute();
while (@fmrow=$sth->fetchrow_array)
{
#print "test\n";

@row=$fmrow[0];
#print "row:$row\n";

}

}
}
else {
#print "table:$table\n";

$sth=$stagedbh->prepare(qq/select status_flag from $table/);
$sth->execute();
while (@fmrow=$sth->fetchrow_array)
{
#print "test\n";

@row=$fmrow[0];
#print "row:$row\n";


}
}
$flag=0;
foreach $row(@row){
if ($row=='1' || $row=='2'){
$flag=1;
#print "shutdown!\n";

}
elsif ($row=='0'){
#print "row:$row\n";

#print "table:$table\n";

$trth=$stagedbh->prepare(qq/select transaction_id from transaction_tbl where dst_tbl="$table"/);

$trth->execute();
while (@row=$trth->fetchrow_array)
{
 $id=@row[0];
#print $id."\n";

}
$quth=$stagedbh->prepare(qq/select src_tbl from transaction_tbl where transaction_id="$id" && seq="1"/);
$quth->execute();
while (@qu_name=$quth->fetchrow_array)
{
$queuename=$row[0];
}
$re_ran="$ws2/re-ran.pl $queuename";
print "###now start re-transaction records######\n$re_ran\n";
system "$re_ran";
}
  }
}
#print "flag:$flag\n";

if ($flag==1){
print "stop crond and mysql!\n";
system "/etc/init.d/crond stop";
system "/sbin/service mysqld stop";

}
$sth->finish();
$stagedbh->disconnect();

#!/bin/sh

# chain policies
# set default policies
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -P FORWARD ACCEPT

# flush tables
/sbin/iptables -F
/sbin/iptables -F INPUT
/sbin/iptables -F OUTPUT
/sbin/iptables -F FORWARD
/sbin/iptables -F -t mangle
/sbin/iptables -X
/sbin/iptables -F -t nat

# loopback rules
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT

/sbin/iptables -A INPUT -i eth0 -p tcp --dport 3306 -j REJECT
/sbin/iptables -A INPUT -i eth0 -p udp --dport 3306 -j REJECT

阅读(242) | 评论(0) | 转发(0) |
0

上一篇:showqueuename.pl

下一篇:startwservices.pl

给主人留下些什么吧!~~