锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲色无码专区一区,老司机亚洲精品影院在线观看,亚洲AV无码乱码在线观看性色扶http://www.tkk7.com/ruoyoux/category/40789.html涓烘ⅵ鎯寵屾潵錛屼負(fù)鑷敱鑰岀敓銆? 鎬ф儏鑻ユ按錛岄璧鋒按鍏達(dá)紝椋庢伅姘存錛屾晠鏃惰屾縺鑽★紝鏃跺張娓呭鉤鈥︹?/description>zh-cnFri, 07 Aug 2009 08:52:41 GMTFri, 07 Aug 2009 08:52:41 GMT60姣忔棩涓璁?2009/08/06 perl socket script http://www.tkk7.com/ruoyoux/articles/290071.htmlBlog of JoJoBlog of JoJoThu, 06 Aug 2009 04:11:00 GMThttp://www.tkk7.com/ruoyoux/articles/290071.htmlhttp://www.tkk7.com/ruoyoux/comments/290071.htmlhttp://www.tkk7.com/ruoyoux/articles/290071.html#Feedback0http://www.tkk7.com/ruoyoux/comments/commentRss/290071.htmlhttp://www.tkk7.com/ruoyoux/services/trackbacks/290071.html entirety.
It would be taylored to only execute one
command not an open perl script. Better
than having root .rhosts everywhere.
I think where it does the:

print F $Line;

at the bottom is where I could put some
kind of execute statement.
Take the string and run it not print it
to a file.



socket.client.perl
#!/usr/bin/perl
#===============================================
# Client -- using object interface
# Support Windows and UNIX
#===============================================
use IO::Socket;
my $sock = new IO::Socket::INET (
PeerAddr => '128.166.11.13',
PeerPort => '9999',
Proto => 'tcp',
);
die "Could not create socket: $!"n" unless $sock;
print $sock "Hi there!"n";
$sock->send("Hi again!"n");

close($sock);


socket.server.perl
#!/usr/bin/perl
#===============================================
# Server -- using object interface
# Support Windows and UNIX
#===============================================

#use Proc::Daemon;
use IO::Socket;
#Proc::Daemon::Init();

use POSIX qw(setsid);

sub daemonize {
die "Can't fork" unless defined (my $child = fork());
exit 0 if $child;
setsid();
open(STDIN, "</dev/null");
open(STDOUT, ">/dev/null");
open(STDERR, ">&STDOUT");
chdir '/';
umask(0);
#$ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin';
return $$;
};

&daemonize;
while() {
my $new_sock = $sock->accept();

####################################
# Put a message to file. #
####################################

while(defined($Line = <$new_sock>)) {
open (F,"+>>/lhome/root/testfile.txt");
print F $Line;
close F;
};
close($sock);
}; #End of while cycle
A. Clay Stephenson Expert in this area This member has accumulated 80000 or more points     
May 21, 2004 16:47:45 GMT  10 pts     
In that case, $Line has your input so you can use it to execute whatever you like.

Typically, your client should send a formatted request string of some type. I like to use <tabs> to separate the fields and then your server responds each time it sees a new line of input.



------------------------------------------------------------------------------------------------------

All I am saying in that any client/server architecture, you must establish some sort of protocol.

Let's suppose that your server does 4 things:
1) lists files in a dedicated directories
2) removes 1 file
3) add's a line to an existing file
4) kill the server

Your create client requests that adhere to this, for example, you formant your protocol like this
request_code<tab>string1<tab>string2<LF>

Now every line sent to the server expects these 3 arguments -- although some may simply be dummy args. Tabs are nice because unlike spaces or colons or commas they are not typically part of strings. Typically the request_code is something very easy to parse; e.g 1 - list; 2 - remove, 4 - kill,kill,kill

If you wanrt to see some examples of this along with a little explanation, go to www.sysadminmag.com and look under the April '03 issue. I wrote an article that used Perl a Perl client/server pair to implement multi-host semaphores. Their web page also has a source code link where you will find the client and server pieces.

-----------------------------------------------------------------------------------------------

For now though. I just wanted something
simple to get around the root .rhosts problem. I was thinking as a security measure
of passing a code to the server.pl but don't
know the perl syntax at this time.
Could you show me the simple syntax for
passing two args.

e.g.

From client.pl send:

1234 shutdown.sh

On server.pl check code then run command:

1234 shutdown.sh


On my client.perl I currently have:

print $sock "shutdown.sh"

On my server.perl I have:

while(defined($Line = <$new_sock>)) {
system($Line);
close($sock);
}; #End



]]>
姣忔棩涓璁?2009/08/06 use ssh to execute perl script remotelyhttp://www.tkk7.com/ruoyoux/articles/290070.htmlBlog of JoJoBlog of JoJoThu, 06 Aug 2009 04:08:00 GMThttp://www.tkk7.com/ruoyoux/articles/290070.htmlhttp://www.tkk7.com/ruoyoux/comments/290070.htmlhttp://www.tkk7.com/ruoyoux/articles/290070.html#Feedback0http://www.tkk7.com/ruoyoux/comments/commentRss/290070.htmlhttp://www.tkk7.com/ruoyoux/services/trackbacks/290070.html#!/opt/TLCLperl/bin/perl -w
#!/usr/local/bin/perl -w

#
# use ssh to execute perl script remotely
#

# You can change PERL and REMOTE_CMD constants to reflect your real
# environment...

use constant PERL => 'perl'; # maybe "/usr/local/bin/perl"
use constant REMOTE_CMD => 'ssh';
use constant CAT_CMD => 'cat';

use strict;
use vars qw($VERSION);
$VERSION = '1.00';

use constant USAGE => <<EOU;

Usage:

$0 ""
[-v] ""
[-r<remote command flags>] ""
[-R<remote command>] ""
[-Q<perl path>] ""
[<usual perl flags>] ""
<[<remote user>@]remote_host>[,...] ""
[<local_script.pl | -e 'perl code'>] ""
[<script args>]

EOU

# options for command line parsing
my $verbose; # -v
my @remote_opts; # opts for ssh/remote command
my $remote_cmd; # ssh substitute
my @perl_opts; # opts for remote perl
my $perl_cmd; # remote perl path

# extract options. This is very simple parsing of options and force
# the args to be precisely ordered.
while(defined $ARGV[0] and $ARGV[0]=~/^-/) {
$_=shift;
if (/^-v/) { $verbose=1 }
elsif (/^-r(.*)/) { push @remote_opts,$1 }
elsif (/^-R(.*)/) { $remote_cmd=$1 }
elsif (/^-Q(.*)/) { $perl_cmd=$1 }
else { push @perl_opts,"'$_'" }
}

# use the default REMOTE_CMD
$remote_cmd||=REMOTE_CMD;

# read remote machine name:
my $machines=shift or die "error: remote machine not specified"n".USAGE;
my @machines=split(',',$machines);

# script name... when available:
my $file=shift;

# get the perl code to run remotely:
my $code;
if(defined $file and $file eq '-e') {
# perl code is in cmd line after the -e switch.
$code=shift or die "error: no perl code after '-e'"n".USAGE;
}
else {
if (defined $file) {
if($file=~/(.+):(.+)/) {
# read perl code from remote file
open(F,"$remote_cmd '$1' ".CAT_CMD." '$2'|")
or die "error: unable to read remote file '$2' from '$1' ($!)"n";
}
else {
# read perl code from file.
open(F,"< $file")
or die "error: unable to open '$file' ($!)"n";
}
}
else { *F=*STDIN } # read perl code from stdin
{
# slurp the file to $code
local $/=undef;
$code=<F>;
}
# gets perl path and flags for first line in src file if available:
if ($code=~/"A"#!(.*)$/m) {
my $line=$1;
if ($line=~/"s*("S+)"s*(.*)/) {
$perl_cmd||=$1;
# anything in the line after the perl path will be considered to
# be flags. I know this could be improved.
push @perl_opts,$2 if defined $2;
}
}
}

# use the default PERL location if it is yet unknow
$perl_cmd||=PERL;

# convert code to hex string
my $packed = unpack "h*",$code;

# this is the remote program to decode and run the script:
my $decoder = q{'BEGIN{eval"sub _R{".(pack"h*",shift)."}"}_R(@ARGV)'};
# There was a simpler decoder but it didn't works with the -n flag so
# I have changed it...
# my $decoder = q{'eval pack"h*",shift'};

# format script args with "'" between them:.
my $args='';
{
local $"="' '";
$args="'@ARGV'" if @ARGV;
}

foreach my $machine (@machines) {
# complete ssh cmd. Remote command is escaped.
my $cmd="$remote_cmd @remote_opts $machine ".
quotemeta "$perl_cmd @perl_opts -e $decoder $packed $args";

# print cmd if verbosity enabled
print STDERR "remote cmd:"n$cmd"n"n" if $verbose;

# run it and report problems
system($cmd)
and print STDERR "Unable to exec ($!)."nRemote command was:"n$cmd"n"n";
}

#################################################
# documentation:


=head1 NAME

sperl - runs perl scripts in remote machines through ssh


=head1 SCRIPT CATEGORIES

Networking
UNIX/System_administration
Perl/Utilities


=head1 README

sperl is some kind of enhanced perl that lets you work in a network
environment and run scripts and oneliners in remote machines without
the need to


=head1 USAGE

$ sperl "
[-v] "
[-r<remote command flags>] "
[-R<remote command>] "
[-Q<perl path>] "
[<usual perl flags>] "
<[<remote user>@]remote_host>[,...] "
[<[<[<user>@]machine>:]script.pl | -e 'perl code'>] "
[<script args>]


=head1 INSTALLATION

To install sperl, copy it to some place in your path like
/usr/local/bin/sperl and allow execution of it with C<chmod 755
/your/path/to/sperl>.

If you want, you can edit the script and change the PERL and
REMOTE_CMD constants at the beginning to match your real environment.


=head1 DESCRIPTION

C<sperl> lets you run a locally stored perl script in a remote machine
for which ssh (or equivalent) access is available.

It doesn't need any special module installed in local or remote
machines, just plain perl.

If there isn't script name in the command line, neither C<-e> option,
sperl will try to read the code form stdin as perl use to do.

It's possible to take the script file from another remote machine
with the syntax C<machine:/path/to/script.pl> or even
C<user@machine:/path/to/script.pl>.

It's also possible to include several remote host names separated by
commas and the script will be run in all of them. For example C<hippo,bugs,bill@www.microsoft.com>


=head1 OPTIONS

C<sperl> accepts the same command line options as C<perl> does. The
options are passed unchanged to the remote perl interpreter so some of
them like C<-S> are nonsense.

Additionally, it accepts some specific options:

=over

=item -rE<lt>remote command flagsE<gt>

pass options to ssh. For instance C<-r-v>

=item -RE<lt>remote commandE<gt>

specify the command to use in place of ssh to connect to the remote
machine. for instance C<-Rrsh>.

=item -QE<lt>remote perl pathE<gt>

specify the location of the perl interpreter in the remote
machine. By default, sperl will try to look for the perl path in the
script first line, if it uses the notation C<#!/path/to/perl>. As its
last resource it expects perl to be in the PATH.

=item -v

dumps the remote command to stderr before running it. This is primary
for debugging purposes.

=back


=head1 EXAMPLES

[salvador@hippo:~]$ sperl admin@willy "
> -e 'print "hello from ".`hostname`'
hello from willy

# the -t option force ssh to allocate a new tty...
[salvador@hippo:~]$ sperl -w -r-t willy -e 'print $count+1,""n"'
Use of uninitialized value at (eval 1) line 1.
1

# you can even invoke the perl debugger remotely:
[salvador@hippo:~]$ sperl -d -r-t willy -e 1

Loading DB routines from perl5db.pl version 1.0401
Emacs support available.

Enter h or `h h' for help.

main::(-e:1): BEGIN{eval"sub _R{".(pack"h*",shift)."}"}_R(@ARGV)
DB<1> p `hostname`
p `hostname`
willy

DB<2> ...

# running the same code in several machines:
[salvador@hippo:~]$ sperl bugs,willy,hippo -e "
> 'chomp($h=`hostname`);print "hello from $h!!!"n"'
hello from bugs!!!
hello from willy!!!
hello from hippo!!!



=head1 CHANGES

=over

=item sperl 1.00 Thu Sep 23 1999

First public release

=back


=head1 BUGS AND LIMITATIONS

This is a beta release so expect errors in it.

Lots of spelling errors in the docs... Help me!!!

The order of the options in the command line is very inflexible.

Switch parsing for the first line of the script is not very clever and
it will produce unexpected results if something complex is there.

Scripts with C<__END__> or C<__DATA__> sections will fail.

I don't know if there is any possibility to make this to work in
Microsoft's world.


=head1 AUTHOR

Salvador Fandiño García <salvador@cesat.es, fandino@usa.net>


=head1 SEE ALSO

L<perl(1)>, L<ssh(1)> or L<rsh(1)>, L<perlrun(1)>.


=cut


]]>
姣忔棩涓璁?2009/08/06 How to execute a perl script at remote server [My problem]http://www.tkk7.com/ruoyoux/articles/290069.htmlBlog of JoJoBlog of JoJoThu, 06 Aug 2009 04:06:00 GMThttp://www.tkk7.com/ruoyoux/articles/290069.htmlhttp://www.tkk7.com/ruoyoux/comments/290069.htmlhttp://www.tkk7.com/ruoyoux/articles/290069.html#Feedback0http://www.tkk7.com/ruoyoux/comments/commentRss/290069.htmlhttp://www.tkk7.com/ruoyoux/services/trackbacks/290069.html    
    I have written a Perl script, which deals with the ftp ing
(transferring) the file to remote server and executing a Perl script
(AUT) at remote m/c.

The script is as below and here I have 2 doubts, so please help me to
resolve this.
1) I am getting the message like "could not transfer the file to
server" but it is ftp ing the flie to remote m/c, and I can see that
file ( root1.txt ) there.

2) And I want to run the perl script (AUT) at remote m/c depending
on the data we sent, so could you please let me know how can I achieve
this.

Is it possible for me to do system("test.pl"),  If I am at SFTP mode.
Please see comment line in the code below.



#!/usr/bin/perl -w

use strict;
use warnings;
use Net::SFTP;

my $server="A.BY.C.D";
my $user="roserag";
my $password="june@123";
my %args = (user => "$user", password => "$password", ssh_args => []);
$args{debug} = 1;
$args{user} = "root";
my $file="local.txt";
my $rfile = "root1.txt";

my $sftp=Net::SFTP->new($server, %args) or die "could not open
connection to $server"n";
$sftp->put($file,$rfile) or die " could not transfer the file to server
"n";


# system("test.pl");    Is this command work out.

exit;


[gaurav@testbrix Examples]$ perl sftp3.pl
testbrix.wipro.com: Reading configuration data /home/gaurav/.ssh/config
testbrix.wipro.com: Reading configuration data /etc/ssh_config
...................................
...................................
testbrix.wipro.com: sftp: In write loop, got 510 offset 0
testbrix.wipro.com: sftp: Sent message T:10 I:2
testbrix.wipro.com: sftp: Sent message T:4 I:3
could not transfer the file to server

But I can see the file the file at server.


Regards,
XXX


Please do not print this email unless it is absolutely necessary.
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com



]]>
姣忔棩涓璁?2009/07/31 Create Glassfish Cluster in Windownshttp://www.tkk7.com/ruoyoux/articles/289240.htmlBlog of JoJoBlog of JoJoFri, 31 Jul 2009 03:55:00 GMThttp://www.tkk7.com/ruoyoux/articles/289240.htmlhttp://www.tkk7.com/ruoyoux/comments/289240.htmlhttp://www.tkk7.com/ruoyoux/articles/289240.html#Feedback0http://www.tkk7.com/ruoyoux/comments/commentRss/289240.htmlhttp://www.tkk7.com/ruoyoux/services/trackbacks/289240.html @echo off

set DOMAIN=domain1
set CLUSTER=server


set MASTERIP=127.0.0.1
set NODE1=agent1

set INSTANCE1=ps1
set NODE2=agent2
set INSTANCE2=ps2

if "%1" == "" goto :ERROR

if "%2" == "" goto :ERROR

call %1"bin"asadmin stop-domain domain1

xcopy classes"*.* /s %1"domains"domain1"lib"classes
copy mysql-connector-java-5.1.5-bin.jar %1"domains"domain1"lib"ext

call %1"bin"asadmin start-domain domain1

call %1"bin"asadmin set server.java-config.classpath-suffix=%1"domains"domain1"lib"ext"mysql-connector-java-5.1.5-bin.jar
call %1"bin"asadmin set server.java-config.classpath-suffix=${com.sun.aas.instanceRoot}/lib/classes
call %1"bin"asadmin set server.system-property.com_outblaze_config_cobrand="C:"config"

call %1"bin"asadmin create-auth-realm --classname com.outblaze.glassfish.security.OBAppservRealm --property auth-type=obRealm:jaas-context=obRealm --target server obRealm

echo obRealm {com.outblaze.glassfish.security.OBPasswordLoginModule required;}; >> %1"domains"domain1"config"login.conf



call %1"bin"asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlXADataSource --restype javax.sql.XADataSource --isolationlevel read-committed --isisolationguaranteed --property User=root:Password=123:URL=jdbc":mysql"://localhost/pointsystem_sd --target server mysqlPool

call %1"bin"asadmin create-jdbc-resource --connectionpoolid mysqlPool --target server jndi/cobrandpsDS

call %1"bin"asadmin delete-jdbc-connection-pool --cascade=true --target server mysqlPoolOffline

call %1"bin"asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlXADataSource --restype javax.sql.XADataSource --isolationlevel read-committed --isisolationguaranteed --property User=root:Password=123:URL=jdbc":mysql"://localhost/pointsystem_off --target server mysqlPoolOffline

call %1"bin"asadmin create-jdbc-resource --connectionpoolid mysqlPoolOffline --target server jndi/cobrandpsDS_of

call %1"bin"asadmin delete-jdbc-connection-pool --cascade=true --target server mysqlPoolLog

call %1"bin"asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlXADataSource --restype javax.sql.XADataSource --isolationlevel read-committed --isisolationguaranteed --property User=root:Password=123:URL=jdbc":mysql"://localhost/wslog_stats_db --target server mysqlPoolLog

call %1"bin"asadmin create-jdbc-resource --connectionpoolid mysqlPoolLog --target server jndi/cobrandpsDS_log

call %1"bin"asadmin delete-jdbc-connection-pool --cascade=true --target server itemmallsqlPool

call %1"bin"asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlXADataSource --restype javax.sql.XADataSource --isolationlevel read-committed --isisolationguaranteed --property User=root:Password=123:URL="jdbc":mysql"://localhost/obcart" --target server itemmallsqlPool

call %1"bin"asadmin create-jdbc-resource --connectionpoolid itemmallsqlPool --target server jndi/itemmallDS

call %1"bin"asadmin delete-jdbc-connection-pool --cascade=true --target server mysqlPoolpsClusterTimer
call %1"bin"asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlXADataSource --restype javax.sql.XADataSource --isolationlevel read-committed --isisolationguaranteed --property User=root:Password=123:URL="jdbc":mysql"://localhost/glassfishtimer" --target server mysqlPoolpsClusterTimer
call %1"bin"asadmin create-jdbc-resource --connectionpoolid mysqlPoolpsClusterTimer --target server jndi/ps_cluster_timer
call %1"bin"asadmin set --user admin --port 4848 server-config.ejb-container.ejb-timer-service.timer-datasource=jndi/ps_cluster_timer


echo prepare for MQ
echo =============================================================================
call %1"bin"asadmin delete-jmsdest  --desttype queue --target server ActiveMqQueue
call %1"bin"asadmin delete-admin-object --target server jms/ActiveMqQueue
call %1"bin"asadmin delete-connector-resource --target server jms/ActiveMQConnectionFactory
call %1"bin"asadmin delete-connector-connection-pool --target server jms/ActiveMQpool
call %1"bin"asadmin undeploy --target server activemq-rar-5.1.0
echo finished prepare for MQ
echo =============================================================================

echo start config for MQ
echo --------------------------------------------------------------------------------
XCOPY activeMQ_config"bin"*.* %2"bin" /k /y /z
XCOPY activeMQ_config"conf"*.* %2"conf /k /y /z
XCOPY activeMQ_config"webapps"admin"*.* %2"webapps"admin" /k /y /z
XCOPY activeMQ_config"webapps"admin"decorators"*.* %2"webapps"admin"decorators" /k /y /z
XCOPY activeMQ_config"webapps"admin"WEB-INF"*.* %2"webapps"admin"WEB-INF" /k /y /z


call %1"bin"asadmin deploy --user admin --host localhost --port 4848 --target server activemq-rar-5.1.0.rar
echo finished deploying activemq-rar-5.1.0.rar

call %1"bin"asadmin create-admin-object --raname activemq-rar-5.1.0 --restype javax.jms.Queue --property DestinationJndiName=ActiveMqQueue --target server jms/ActiveMqQueue
echo finished create admin object jms/ActiveMqQueue

call %1"bin"asadmin create-jmsdest --desttype queue --target server ActiveMqQueue
echo finished create jmsdest ActiveMqQueue

call %1"bin"asadmin create-connector-connection-pool --raname activemq-rar-5.1.0 --connectiondefinition javax.jms.ConnectionFactory --transactionsupport  XATransaction --target server jms/ActiveMQpool
echo finished create connector connection pool jms/ActiveMQpool

call %1"bin"asadmin create-connector-resource --poolname jms/ActiveMQpool --target server jms/ActiveMQConnectionFactory
echo finished create connector resource jms/ActiveMQConnectionFactory

echo MQ Setup complete
echo --------------------------------------------------------------------------------

echo Shutting down Glassfish
call %1"bin"asadmin stop-domain domain1

echo Setup complete
goto :END


:ERROR
echo Please set glassfish base path and activeMQ path.
echo e.g. config-new-glassfish c:"glassfish c:"apache-activemq-5.1.0-bin

:END

]]>
姣忔棩涓璁?2009/07/31 Set Up Glassfish Cluster & Config Sql Connection in Linuxhttp://www.tkk7.com/ruoyoux/articles/289239.htmlBlog of JoJoBlog of JoJoFri, 31 Jul 2009 03:53:00 GMThttp://www.tkk7.com/ruoyoux/articles/289239.htmlhttp://www.tkk7.com/ruoyoux/comments/289239.htmlhttp://www.tkk7.com/ruoyoux/articles/289239.html#Feedback0http://www.tkk7.com/ruoyoux/comments/commentRss/289239.htmlhttp://www.tkk7.com/ruoyoux/services/trackbacks/289239.html #!/bin/bash

# Do not edit below , please supply variable in command line
ACTION=$1
COBRAND=$2
GLASS_FISH=$3
DOMAIN=domain1
MASTERIP=$4
ACTIVEMQ=$5
INSTANCE_NO=$6
JDBC_USER=$7
JDBC_PASSWORD=$8
JDBC_HOST=$9



CLUSTER=ps-$COBRAND-cluster
NODE=ps-$COBRAND-node-$INSTANCE_NO
INSTANCE=ps-$COBRAND-instance-$INSTANCE_NO


function common () {


#those two command should be executed in master and slave machine
cp mysql-connector-java-5.1.5-bin.jar $GLASS_FISH/lib
cp obrealm.jar  $GLASS_FISH/lib
cp -rf activeMQ_config/*  $ACTIVEMQ/

if [ $ACTION = "master" ]; then
$GLASS_FISH/bin/asadmin stop-domain $DOMAIN
$GLASS_FISH/bin/asadmin start-domain $DOMAIN
fi

#run those following lines to stop cluster and node in the master machine
if [ $ACTION = "master" ]; then
$GLASS_FISH/bin/asadmin stop-cluster --user admin --host  $MASTERIP  --port 4848 $CLUSTER
fi
$GLASS_FISH/bin/asadmin stop-node-agent $NODE

#run those following lines to delete node, cluster and instance in the master machine
$GLASS_FISH/bin/asadmin delete-node-agent  $NODE
if [ $ACTION = "master" ]; then
$GLASS_FISH/bin/asadmin delete-cluster  $CLUSTER
fi
$GLASS_FISH/bin/asadmin delete-instance  $INSTANCE


#run those following lines to create node, cluster and instance in the master machine
$GLASS_FISH/bin/asadmin create-node-agent --host $MASTERIP --port 4848 $NODE
if [ $ACTION = "master" ]; then
$GLASS_FISH/bin/asadmin create-cluster --host $MASTERIP --port 4848 $CLUSTER
fi
$GLASS_FISH/bin/asadmin create-instance --host $MASTERIP --port 4848 --nodeagent $NODE --cluster $CLUSTER $INSTANCE



#run those following lines to start node, cluster and instance in the master machine
#bin/asadmin start-node-agent --syncinstances=true $NODE
#bin/asadmin start-cluster --user admin --host $MASTERIP --port 4848 $CLUSTER
#bin/asadmin start-instance --user admin --host $MASTERIP --port 4848 $INSTANCE

}

function master () {

#cp -r classes/* $GLASS_FISH/domains/$DOMAIN/lib/classes/

cp  activemq-rar-5.1.0.rar  $GLASS_FISH/

#those two command should be executed in master and slave machine
cp mysql-connector-java-5.1.5-bin.jar $GLASS_FISH/lib
cp obrealm.jar  $GLASS_FISH/lib

$GLASS_FISH/bin/asadmin stop-domain $DOMAIN
$GLASS_FISH/bin/asadmin start-domain $DOMAIN



$GLASS_FISH/bin/asadmin set $CLUSTER.java-config.classpath-suffix='${com.sun.aas.installRoot}/lib/mysql-connector-java-5.1.5-bin.jar'
$GLASS_FISH/bin/asadmin set $CLUSTER.java-config.classpath-suffix='${com.sun.aas.installRoot}/lib/obrealm.jar'
mkdir -p /usr/local/site/webroot/template/pointsystem/
$GLASS_FISH/bin/asadmin set $CLUSTER.system-property.com_outblaze_config_cobrand='/usr/local/site/webroot/template/pointsystem/'
$GLASS_FISH/bin/asadmin create-auth-realm --classname com.outblaze.glassfish.security.OBAppservRealm --property auth-type=obRealm:jaas-context=obRealm --target $CLUSTER obRealm

echo "obRealm {com.outblaze.glassfish.security.OBPasswordLoginModule required;};" >> $GLASS_FISH/domains/$DOMAIN/config/login.conf

$GLASS_FISH/bin/asadmin  set $CLUSTER.http-service.virtual-server.server.property.accessLoggingEnabled=true
echo "finished setting the access log "

$GLASS_FISH/bin/asadmin delete-jdbc-connection-pool --cascade=true --target $CLUSTER mysqlPool
$GLASS_FISH/bin/asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlXADataSource --restype javax.sql.XADataSource --isolationlevel read-committed --isisolationguaranteed --property User=$JDBC_USER:Password=$JDBC_PASSWORD:URL="jdbc":mysql"://$JDBC_HOST/pointsystem_sd" --target $CLUSTER mysqlPool
$GLASS_FISH/bin/asadmin create-jdbc-resource --connectionpoolid mysqlPool --target $CLUSTER jndi/cobrandpsDS
$GLASS_FISH/bin/asadmin delete-jdbc-connection-pool --cascade=true --target $CLUSTER mysqlPoolOffline
$GLASS_FISH/bin/asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlXADataSource --restype javax.sql.XADataSource --isolationlevel read-committed --isisolationguaranteed --property User=$JDBC_USER:Password=$JDBC_PASSWORD:URL="jdbc":mysql"://$JDBC_HOST/pointsystem_off" --target $CLUSTER mysqlPoolOffline
$GLASS_FISH/bin/asadmin create-jdbc-resource --connectionpoolid mysqlPoolOffline --target $CLUSTER jndi/cobrandpsDS_of
$GLASS_FISH/bin/asadmin delete-jdbc-connection-pool --cascade=true --target $CLUSTER mysqlPoolLog
$GLASS_FISH/bin/asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlXADataSource --restype javax.sql.XADataSource --isolationlevel read-committed --isisolationguaranteed --property User=$JDBC_USER:Password=$JDBC_PASSWORD:URL="jdbc":mysql"://$JDBC_HOST/wslog_stats_db" --target $CLUSTER mysqlPoolLog
$GLASS_FISH/bin/asadmin create-jdbc-resource --connectionpoolid mysqlPoolLog --target $CLUSTER jndi/cobrandpsDS_log
$GLASS_FISH/bin/asadmin delete-jdbc-connection-pool --cascade=true --target $CLUSTER itemmallsqlPool
$GLASS_FISH/bin/asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlXADataSource --restype javax.sql.XADataSource --isolationlevel read-committed --isisolationguaranteed --property User=$JDBC_USER:Password=$JDBC_PASSWORD:URL="jdbc":mysql"://$JDBC_HOST/obcart" --target $CLUSTER itemmallsqlPool
$GLASS_FISH/bin/asadmin create-jdbc-resource --connectionpoolid itemmallsqlPool --target $CLUSTER jndi/itemmallDS

$GLASS_FISH/bin/asadmin delete-jdbc-connection-pool --cascade=true --target $CLUSTER mysqlPoolpsClusterTimer
$GLASS_FISH/bin/asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlXADataSource --restype javax.sql.XADataSource --isolationlevel read-committed --isisolationguaranteed --property User=$JDBC_USER:Password=$JDBC_PASSWORD:URL="jdbc":mysql"://$JDBC_HOST/glassfishtimer" --target $CLUSTER mysqlPoolpsClusterTimer
$GLASS_FISH/bin/asadmin create-jdbc-resource --connectionpoolid mysqlPoolpsClusterTimer --target $CLUSTER jndi/ps_cluster_timer

$GLASS_FISH/bin/asadmin delete-jdbc-connection-pool --cascade=true --target $CLUSTER reportPool
$GLASS_FISH/bin/asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlXADataSource --restype javax.sql.XADataSource --isolationlevel read-committed --isisolationguaranteed --property User=$JDBC_USER:Password=$JDBC_PASSWORD:URL="jdbc":mysql"://$JDBC_HOST/pointsystem_sd" --target $CLUSTER reportPool
$GLASS_FISH/bin/asadmin create-jdbc-resource --connectionpoolid reportPool --target $CLUSTER jndi/reportDS

$GLASS_FISH/bin/asadmin set $CLUSTER-config.ejb-container.ejb-timer-service.timer-datasource=jndi/ps_cluster_timer

#$GLASS_FISH/bin/asadmin create-jvm-options --target $CLUSTER -Dcom.sun.enterprise.web.connector.enableJK=8012
#$GLASS_FISH/bin/asadmin create-jvm-options --target $CLUSTER -DjvmRoute=glassfish1
#$GLASS_FISH/bin/asadmin create-jvm-options --target $CLUSTER -DjvmRoute=glassfish2
#$GLASS_FISH/bin/asadmin set $CLUSTER.java-config.classpath-prefix='${com.sun.aas.installRoot}/lib/patch.jar'
#$GLASS_FISH/bin/asadmin set $CLUSTER.java-config.system-classpath='${com.sun.aas.installRoot}/lib/tomcat-ajp.jar,${com.sun.aas.installRoot}/lib/commons-modeler.jar,${com.sun.aas.installRoot}/lib/commons-logging.jar'


}

function setupmq () {


echo "Prepare for MQ"
echo "============================================================================="
$GLASS_FISH/bin/asadmin delete-jmsdest  --desttype queue --target $CLUSTER ActiveMqQueue
$GLASS_FISH/bin/asadmin delete-admin-object --target $CLUSTER jms/ActiveMqQueue
$GLASS_FISH/bin/asadmin delete-connector-resource --target $CLUSTER jms/ActiveMQConnectionFactory
$GLASS_FISH/bin/asadmin delete-connector-connection-pool --target $CLUSTER jms/ActiveMQpool
$GLASS_FISH/bin/asadmin undeploy --target $CLUSTER activemq-rar-5.1.0
echo "finished prepare for MQ"
echo "============================================================================="


echo "Start config for MQ"
echo "--------------------------------------------------------------------------------"
$GLASS_FISH/bin/asadmin deploy --target $CLUSTER activemq-rar-5.1.0.rar
echo "finished deploying activemq-rar-5.1.0.rar"

$GLASS_FISH/bin/asadmin create-admin-object --raname activemq-rar-5.1.0 --restype javax.jms.Queue --property DestinationJndiName=ActiveMqQueue --target $CLUSTER jms/ActiveMqQueue
echo "finished create admin object jms/ActiveMqQueue"

$GLASS_FISH/bin/asadmin create-jmsdest --desttype queue --target $CLUSTER ActiveMqQueue
echo "finished create jmsdest ActiveMqQueue"

$GLASS_FISH/bin/asadmin create-connector-connection-pool --raname activemq-rar-5.1.0 --connectiondefinition javax.jms.ConnectionFactory --transactionsupport  XATransaction --target $CLUSTER jms/ActiveMQpool
echo "finished create connector connection pool jms/ActiveMQpool"

$GLASS_FISH/bin/asadmin create-connector-resource --poolname jms/ActiveMQpool --target $CLUSTER jms/ActiveMQConnectionFactory
echo "finished create connector resource jms/ActiveMQConnectionFactory"

echo "MQ Setup complete"
echo "--------------------------------------------------------------------------------"


}

if [ $# != 9 ]; then
        echo $"Usage: $prog {master|slave cobrand_name glassfish_path DAS_hostname ActiveMQ_path instance_no mysql_username mysql_password mysql_host}"
        exit 1
fi

case "$1" in
  master)
        common
        master
        setupmq
        ;;
  slave)
        common
        ;;
  *)
        echo $"Usage: $prog {master|slave cobrand_name glassfish_path DAS_hostname ActiveMQ_path instance_no mysql_username mysql_password mysql_host}"
        exit 1
esac



]]>
姣忔棩涓璁?2009/07/29 insert-mysql-statementhttp://www.tkk7.com/ruoyoux/articles/288844.htmlBlog of JoJoBlog of JoJoWed, 29 Jul 2009 02:13:00 GMThttp://www.tkk7.com/ruoyoux/articles/288844.htmlhttp://www.tkk7.com/ruoyoux/comments/288844.htmlhttp://www.tkk7.com/ruoyoux/articles/288844.html#Feedback0http://www.tkk7.com/ruoyoux/comments/commentRss/288844.htmlhttp://www.tkk7.com/ruoyoux/services/trackbacks/288844.html
#!/usr/bin/perl -w

#
# Created by: JoJo
# Created Date: 28 July 2009
# Desc: To create the sql statement for Sanriotown Digital
#

use DateTime;
use DBI;


#open log file for writing, append purpose
open(MYLOGFILE, ">> mylog");


######### Step 1: Create DB Connection  ################################
#definition of variables
$db="UserDB";
$host="localhost";
$socket="/var/lib/auth5-1.us4/mysql1/mysql.sock";
$user="root";
$password="pwd";


#connect to MySQL database
my $dbh   = DBI->connect ("DBI:mysql::mysql_socket=$socket;database=$db:host=$host",$user,$password)
                         or die "Can't connect to database: $DBI::errstr"n";



######### Step 2: Get Active User ################################

# Get date
my $sdt = DateTime->now;
# Get active user ( from userdb, usertype != 8)
print MYLOGFILE "Get all active users from cobranddb.sanriotown_com_userdb tables at  $sdt."n";
#!`echo 'select username from cobranddb.sanriotown_com_userdb where usertype  &8 <> 8 '|mysql -uroot -ppwd --socket=/var/lib/auth5-1.us4/mysql/mysql.sock --skip-column-names >  activeuser.txt` || die print "Cannot connect to cobranddb database."n";
# Get date
my $edt = DateTime->now;
print MYLOGFILE "Finish grep all active users from cobranddb.sanriotown_com_userdb tables at  $edt."n";




######### Step 3: Get Active UserID and Field Value, then Create Insert Statement File#############

# Open active user file for reading
open (USERFILE, 'activeuser.txt');
# Get date
my $s1dt = DateTime->now;
# Get active userid and its field value for "country" filedname whose cobrand is "sanriotown.com"
print MYLOGFILE "Get active userid and its field value for 'country' filedname whose cobrand is 'sanriotown.com' from UserDB.UserProfileTbl and UserDB.UserTbl tables at  $s1dt."n";
while (<USERFILE>) {
  chomp;
  #prepare the query
  my $sql = "select  u.userid, p.fieldvalue from UserDB.UserProfileTbl p, UserDB.UserTbl u where u.cobrand='sanriotown.com' and u.username='$_' and u.userid=p.userid and p.fieldname='country' ";
  my $sth = $dbh->prepare( $sql);
  #execute the query
  $sth->execute( );

  ## Retrieve the results of a row of data and print
  my ( $userid,$fieldvalue);
  $sth->bind_columns ( undef,"$userid,"$fieldvalue );
  while ( $sth->fetch( ) )  {      
      #print MYLOGFILE  "Userid is $userid and the fieldvalue is $fieldvalue"n";
      `echo "insert UserDB.UserProfileTbl values($userid,'orignal_country', '$fieldvalue');" >> insert_sql_statement.sql`;
  }

  $sth->finish( );
}
# Get date
my $e1dt = DateTime->now;
print MYLOGFILE "Finish grep active userid and its field value for 'country' filedname whose cobrand is 'sanriotown.com' from UserDB.UserProfileTbl and UserDB.UserTbl tables at  $e1dt."n";


######### Step 4: Close All File and DB Connection#############

# Close all opened file
close (USERFILE);
close (MYLOGFILE);
$dbh->disconnect( );
exit;



]]>
姣忔棩涓璁?2009/07/21 squid script for supervise purposehttp://www.tkk7.com/ruoyoux/articles/287651.htmlBlog of JoJoBlog of JoJoTue, 21 Jul 2009 06:45:00 GMThttp://www.tkk7.com/ruoyoux/articles/287651.htmlhttp://www.tkk7.com/ruoyoux/comments/287651.htmlhttp://www.tkk7.com/ruoyoux/articles/287651.html#Feedback0http://www.tkk7.com/ruoyoux/comments/commentRss/287651.htmlhttp://www.tkk7.com/ruoyoux/services/trackbacks/287651.html
  • Create directory squid under /service/ to let supervise start Squid automatically
    • Cmd: mkdir -p /service/squid
  • Create a run file in /service/squid with the following content
    • /service/squid/run
      #!/bin/sh
      if (test `ps -e | grep -c squid` = 0)
      then
      {
      echo "no squid is running, clean up pid file";
      rm -f /usr/local/site/squid/logs/squid.pid
      }
      fi
      exec /usr/local/site/squid/bin/squid -N
  • Change the permission to 755, so supervise can run it automatically
    Cmd
    chmod 755 /service/squid/run
    • Note: You can verify if a service is started by supervise correctly by typing the following command.
      • Cmd: svstat /service/*
    • Note: Squid cannot start until you fill /usr/local/site/webroot/errordoc/squid/ with corresponding content later.
    • Note: If Squid appears to restart and fail in one second over and over again by itself, check the owner of the folder /usr/local/site/squid/var/cache/ is mdrop:mdrop. And don't forget to create the swap folder for Squid. (Squid -z option)


  • ]]>
    姣忔棩涓璁?2009/07/17 mysql init scripthttp://www.tkk7.com/ruoyoux/articles/287087.htmlBlog of JoJoBlog of JoJoFri, 17 Jul 2009 02:02:00 GMThttp://www.tkk7.com/ruoyoux/articles/287087.htmlhttp://www.tkk7.com/ruoyoux/comments/287087.htmlhttp://www.tkk7.com/ruoyoux/articles/287087.html#Feedback0http://www.tkk7.com/ruoyoux/comments/commentRss/287087.htmlhttp://www.tkk7.com/ruoyoux/services/trackbacks/287087.html #!/bin/bash
    #
    # mysqld    This shell script takes care of starting and stopping
    #        the MySQL subsystem (mysqld).
    #
    # chkconfig: - 64 36
    # description:    MySQL database server.
    # processname: mysqld
    # config: /etc/my.cnf.jojo1-1.us1.master.3306
    # pidfile: /var/run/mysqld-$MYSQLD_SUFFIX/mysqld.pid

    # Source function library.
    . /etc/rc.d/init.d/functions

    # Source networking configuration.
    . /etc/sysconfig/network

    MYSQLD_SUFFIX="jojo1-1.us1.master.3306"
    MYCNF="/etc/my.cnf.$MYSQLD_SUFFIX"

    prog="MySQL"

    # extract value of a MySQL option from config files
    # Usage: get_mysql_option SECTION VARNAME DEFAULT
    # result is returned in $result
    # We use my_print_defaults which prints all options from multiple files,
    # with the more specific ones later; hence take the last match.
    get_mysql_option(){
        #result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
        #if [ -z "$result" ]; then
            # not found, use default
            #result="$3"
        #fi
          result="$3"
    }

    get_mysql_option mysqld datadir "/var/lib/mysql"
    datadir="$result"
    get_mysql_option mysqld socket "$datadir/mysql.sock"
    socketfile="$result"
    get_mysql_option mysqld_safe log-error "/var/log/mysqld-$MYSQLD_SUFFIX.log"
    errlogfile="$result"
    get_mysql_option mysqld_safe pid-file "/var/run/mysqld-$MYSQLD_SUFFIX/mysqld.pid"
    mypidfile="$result"


    start(){
        touch "$errlogfile"
        chown mysql:mysql "$errlogfile"
        chmod 0640 "$errlogfile"
        [ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
        if [ ! -d "$datadir/mysql" ] ; then
            action $"Initializing MySQL database: " /usr/bin/mysql_install_db
            ret=$?
            chown -R mysql:mysql "$datadir"
            if [ $ret -ne 0 ] ; then
            return $ret
            fi
        fi
        chown mysql:mysql "$datadir"
        chmod 0755 "$datadir"
        # Pass all the options determined above, to ensure consistent behavior.
        # In many cases mysqld_safe would arrive at the same conclusions anyway
        # but we need to be sure.
        /usr/bin/mysqld_safe  --defaults-file=$MYCNF  --datadir="$datadir" --socket="$socketfile" "
            --log-error="$errlogfile" --pid-file="$mypidfile" "
            >/dev/null 2>&1 &
        ret=$?
        # Spin for a maximum of N seconds waiting for the server to come up.
        # Rather than assuming we know a valid username, accept an "access
        # denied" response as meaning the server is functioning.
        if [ $ret -eq 0 ]; then
            STARTTIMEOUT=30
            while [ $STARTTIMEOUT -gt 0 ]; do
              RESPONSE=`/usr/bin/mysqladmin -uUNKNOWN_MYSQL_USER ping 2>&1` && break
            echo "$RESPONSE" | grep -q "Access denied for user" && break
            sleep 1
            let STARTTIMEOUT=${STARTTIMEOUT}-1
            done
            if [ $STARTTIMEOUT -eq 0 ]; then
                        echo "Timeout error occurred trying to start MySQL Daemon."
                        action $"Starting $prog: " /bin/false
                        ret=1
                else
                        action $"Starting $prog: " /bin/true
                fi
        else
                action $"Starting $prog: " /bin/false
        fi
        [ $ret -eq 0 ] && touch /var/lock/subsys/mysqld.$MYSQLD_SUFFIX
        return $ret
    }

    stop(){
            MYSQLPID=`cat "$mypidfile"  2>/dev/null `
            if [ -n "$MYSQLPID" ]; then
                /bin/kill "$MYSQLPID" >/dev/null 2>&1
                ret=$?
                if [ $ret -eq 0 ]; then
                    STOPTIMEOUT=60
                    while [ $STOPTIMEOUT -gt 0 ]; do
                        /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break
                        sleep 1
                        let STOPTIMEOUT=${STOPTIMEOUT}-1
                    done
                    if [ $STOPTIMEOUT -eq 0 ]; then
                        echo "Timeout error occurred trying to stop MySQL Daemon."
                        ret=1
                        action $"Stopping $prog: " /bin/false
                    else
                        rm -f /var/lock/subsys/mysqld.$MYSQLD_SUFFIX
                        rm -f "$socketfile"
                        action $"Stopping $prog: " /bin/true
                    fi
                else
                    action $"Stopping $prog: " /bin/false
                fi
            else
                ret=1
                action $"Stopping $prog: " /bin/false
            fi
            return $ret
    }
     
    restart(){
        stop
        start
    }

    mystatus(){
     MYSQLPID=`cat "$mypidfile"  2>/dev/null `

     if [ -n "$MYSQLPID"  ];
     then
          echo "mysqld-$MYSQLD_SUFFIX is running"
     else
          echo "mysqld-$MYSQLD_SUFFIX is not running"
     fi
    }

    condrestart(){
        [ -e /var/lock/subsys/mysqld.$MYSQLD_SUFFIX ] && restart || :
    }

    # See how we were called.
    case "$1" in
      start)
        start
        ;;
      stop)
        stop
        ;;
      status)
        #status -p "$mypidfile"  mysqld
        mystatus
        ;;
      restart)
        restart
        ;;
      condrestart)
        condrestart
        ;;
      *)
        echo $"Usage: $0 {start|stop|status|condrestart|restart}"
        exit 1
    esac

    exit $?


    ***********************************************************
    [mdrop@jojo1-1 init.d]$ cat /etc/my.cnf.jojo1-1.us1.master.3306
    [mysqld]
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock

    port=3306
    set-variable = thread_cache_size=950
    set-variable = table_cache=4200
    set-variable = key_buffer_size=400M
    set-variable = record_buffer=100000
    set-variable = max_connect_errors=9999999999
    set-variable = max_connections=1700
    set-variable = tmp_table_size=10M
    transaction-isolation = READ-UNCOMMITTED
    set-variable = wait_timeout=180
    set-variable = max_write_lock_count=120
    skip-name-resolve
    skip-locking
    skip-innodb
    set-variable = query_cache_type=1
    set-variable = query_cache_size=52428800
    log-slow-queries
    memlock

    set-variable = max_binlog_size=10M
    log-bin=/var/lib/mysql/jojo1-1-us1-log-bin
    log-bin-index=/var/lib/mysql/jojo1-1-us1-log-bin.index
    server-id=1
        
    [mysql.server]
    user=mysql
    basedir=/var/lib

    [safe_mysqld]
    err-log=/var/lib/mysql/mysqld.log
    pid-file=/var/lib/mysql/mysqld.pid


    ##################################################



    [mdrop@jojo1-1 init.d]$ cat mysqld.jojo1-2.us1.slave.3307
    #!/bin/bash
    #
    # mysqld    This shell script takes care of starting and stopping
    #        the MySQL subsystem (mysqld).
    #
    # chkconfig: - 64 36
    # description:    MySQL database server.
    # processname: mysqld
    # config: /etc/my.cnf.jojo1-2.us1.slave.3307
    # pidfile: /var/run/mysqld.jojo1-2.slave/mysqld.pid

    # Source function library.
    . /etc/rc.d/init.d/functions

    # Source networking configuration.
    . /etc/sysconfig/network

    MYSQLD_SUFFIX="jojo1-2.us1.slave.3307"
    MYCNF="/etc/my.cnf.$MYSQLD_SUFFIX"

    prog="MySQL"

    # extract value of a MySQL option from config files
    # Usage: get_mysql_option SECTION VARNAME DEFAULT
    # result is returned in $result
    # We use my_print_defaults which prints all options from multiple files,
    # with the more specific ones later; hence take the last match.
    get_mysql_option(){
        #result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
        #if [ -z "$result" ]; then
            # not found, use default
            #result="$3"
        #fi
          result="$3"
    }

    get_mysql_option mysqld datadir "/var/lib/mysql1"
    datadir="$result"
    get_mysql_option mysqld socket "$datadir/mysql.sock"
    socketfile="$result"
    get_mysql_option mysqld_safe log-error "/var/log/mysqld-$MYSQLD_SUFFIX.log"
    errlogfile="$result"
    get_mysql_option mysqld_safe pid-file "/var/run/mysqld-$MYSQLD_SUFFIX/mysqld.pid"
    mypidfile="$result"


    start(){
        touch "$errlogfile"
        chown mysql:mysql "$errlogfile"
        chmod 0640 "$errlogfile"
        [ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
        if [ ! -d "$datadir/mysql" ] ; then
            action $"Initializing MySQL database: " /usr/bin/mysql_install_db
            ret=$?
            chown -R mysql:mysql "$datadir"
            if [ $ret -ne 0 ] ; then
            return $ret
            fi
        fi
        chown mysql:mysql "$datadir"
        chmod 0755 "$datadir"
        # Pass all the options determined above, to ensure consistent behavior.
        # In many cases mysqld_safe would arrive at the same conclusions anyway
        # but we need to be sure.
        /usr/bin/mysqld_safe  --defaults-file=$MYCNF  --datadir="$datadir" --socket="$socketfile" "
            --log-error="$errlogfile" --pid-file="$mypidfile" "
            >/dev/null 2>&1 &
        ret=$?
        # Spin for a maximum of N seconds waiting for the server to come up.
        # Rather than assuming we know a valid username, accept an "access
        # denied" response as meaning the server is functioning.
        if [ $ret -eq 0 ]; then
            STARTTIMEOUT=30
            while [ $STARTTIMEOUT -gt 0 ]; do
            RESPONSE=`/usr/bin/mysqladmin -uUNKNOWN_MYSQL_USER ping 2>&1` && break
            echo "$RESPONSE" | grep -q "Access denied for user" && break
            sleep 1
            let STARTTIMEOUT=${STARTTIMEOUT}-1
            done
               
            if [ $STARTTIMEOUT -eq 0 ]; then
                        echo "Timeout error occurred trying to start MySQL Daemon."
                        action $"Starting $prog: " /bin/false
                        ret=1
                else
                        action $"Starting $prog: " /bin/true
                fi
        else
                action $"Starting $prog: " /bin/false
        fi
        [ $ret -eq 0 ] && touch /var/lock/subsys/mysqld.$MYSQLD_SUFFIX
        return $ret
    }

    stop(){
            MYSQLPID=`cat "$mypidfile"  2>/dev/null `
            if [ -n "$MYSQLPID" ]; then
                /bin/kill "$MYSQLPID" >/dev/null 2>&1
                ret=$?
                if [ $ret -eq 0 ]; then
                    STOPTIMEOUT=60
                    while [ $STOPTIMEOUT -gt 0 ]; do
                        /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break
                        sleep 1
                        let STOPTIMEOUT=${STOPTIMEOUT}-1
                    done
                    if [ $STOPTIMEOUT -eq 0 ]; then
                        echo "Timeout error occurred trying to stop MySQL Daemon."
                        ret=1
                        action $"Stopping $prog: " /bin/false
                    else
                        rm -f /var/lock/subsys/mysqld.$MYSQLD_SUFFIX
                        rm -f "$socketfile"
                        action $"Stopping $prog: " /bin/true
                    fi
                else
                    action $"Stopping $prog: " /bin/false
                fi
            else
                ret=1
                action $"Stopping $prog: " /bin/false
            fi
            return $ret
    }
     
    restart(){
        stop
        start
    }

    mystatus(){
     MYSQLPID=`cat "$mypidfile"  2>/dev/null `

     if [ -n "$MYSQLPID"  ];
     then
          echo "mysqld-$MYSQLD_SUFFIX is running"
     else
          echo "mysqld-$MYSQLD_SUFFIX is not running"
     fi
    }



    condrestart(){
        [ -e /var/lock/subsys/mysqld.$MYSQLD_SUFFIX ] && restart || :
    }

    # See how we were called.
    case "$1" in
      start)
        start
        ;;
      stop)
        stop
        ;;
      status)
        #status mysqld
        mystatus
        ;;
      restart)
        restart
        ;;
      condrestart)
        condrestart
        ;;
      *)
        echo $"Usage: $0 {start|stop|status|condrestart|restart}"
        exit 1
    esac

    exit $?

    **********************************************
    [mdrop@jojo1-1 init.d]$ cat /etc/my.cnf.jojo1-2.us1.slave.3307
    [mysqld]
    datadir=/var/lib/mysql1
    socket=/var/lib/mysql1/mysql.sock
    port=3307
    set-variable = thread_cache_size=950
    set-variable = table_cache=4200
    set-variable = key_buffer_size=400M
    set-variable = record_buffer=100000
    set-variable = max_connect_errors=9999999999
    set-variable = max_connections=950
    set-variable = tmp_table_size=10M
    transaction-isolation = READ-UNCOMMITTED
    set-variable = wait_timeout=500
    set-variable = max_write_lock_count=120
    skip-name-resolve
    skip-locking
    skip-innodb
    set-variable = query_cache_type=1
    set-variable = query_cache_size=52428800
    log-slow-queries
    memlock

    master-host=192.168.8.73
    master-user=repl
    master-password=repl12
    master-port=3307
    master-connect-retry=60
    server-id=6239
    set-variable = report-host=jojo1-1.us1.outblaze.com:3307

    [mysql.server]
    user=mysql

    [safe_mysqld]
    err-log=/var/lib/mysql1/mysqld.log
    pid-file=/var/lib/mysql1/mysqld.pid




    ]]>
    姣忔棩涓璁?2009/06/16 寮鏈烘椂鑷姩鍚姩APACHE鐨凷CRIPThttp://www.tkk7.com/ruoyoux/articles/282520.htmlBlog of JoJoBlog of JoJoTue, 16 Jun 2009 01:31:00 GMThttp://www.tkk7.com/ruoyoux/articles/282520.htmlhttp://www.tkk7.com/ruoyoux/comments/282520.htmlhttp://www.tkk7.com/ruoyoux/articles/282520.html#Feedback0http://www.tkk7.com/ruoyoux/comments/commentRss/282520.htmlhttp://www.tkk7.com/ruoyoux/services/trackbacks/282520.html #
    # httpd        Startup script for the Apache HTTP Server
    #
    # chkconfig: 345 85 15
    # description: Apache is a World Wide Web server.  It is used to serve "
    #              HTML files and CGI.
    # processname: httpd
    # config: /usr/local/site/apache/conf/httpd.conf
    # config: /etc/sysconfig/httpd
    # pidfile: /usr/local/site/apache/logs/httpd.pid

    # Source function library.
    . /etc/rc.d/init.d/functions

    if [ -f /etc/sysconfig/httpd ]; then
            . /etc/sysconfig/httpd
    fi

    # Start httpd in the C locale by default.
    HTTPD_LANG=${HTTPD_LANG-"C"}

    # This will prevent initlog from swallowing up a pass-phrase prompt if
    # mod_ssl needs a pass-phrase from the user.
    INITLOG_ARGS=""

    # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
    # with the thread-based "worker" MPM; BE WARNED that some modules may not
    # work correctly with a thread-based MPM; notably PHP will refuse to start.

    # Path to the apachectl script, server binary, and short-form for messages.
    apachectl=/usr/sbin/apachectl
    httpd=${HTTPD-/usr/local/site/apache/bin/httpd}
    prog=httpd
    pidfile=${PIDFILE-/usr/local/site/apache/logs/httpd.pid}
    lockfile=${LOCKFILE-/var/lock/subsys/httpd}
    RETVAL=0

    # check for 1.3 configuration
    check13 () {
            CONFFILE=/usr/local/site/apache/conf/httpd.conf
            GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"
            GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"
            GONE="${GONE}AccessConfig|ResourceConfig)"
            if LANG=C grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then
                    echo
                    echo 1>&2 " Apache 1.3 configuration directives found"
                    echo 1>&2 " please read /usr/share/doc/httpd-2.2.3/migration.html"
                    failure "Apache 1.3 config directives test"
                    echo
                    exit 1
            fi
    }

    # The semantics of these two functions differ from the way apachectl does
    # things -- attempting to start while running is a failure, and shutdown
    # when not running is also a failure.  So we just do it the way init scripts
    # are expected to behave here.
    start() {
            echo -n $"Starting $prog: "
            check13 || exit 1
            LANG=$HTTPD_LANG daemon $httpd $OPTIONS
            RETVAL=$?
            echo
            [ $RETVAL = 0 ] && touch ${lockfile}
            return $RETVAL
    }

    # When stopping httpd a delay of >10 second is required before SIGKILLing the
    # httpd parent; this gives enough time for the httpd parent to SIGKILL any
    # errant children.
    stop() {
            echo -n $"Stopping $prog: "
            killproc -d 10 $httpd
            RETVAL=$?
            echo
            [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
    }
    reload() {
        echo -n $"Reloading $prog: "
        if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
            RETVAL=$?
            echo $"not reloading due to configuration syntax error"
            failure $"not reloading $httpd due to configuration syntax error"
        else
            killproc $httpd -HUP
            RETVAL=$?
        fi
        echo
    }

    # See how we were called.
    case "$1" in
      start)
            start
            ;;
      stop)
            stop
            ;;
      status)
            status $httpd
            RETVAL=$?
            ;;
      restart)
            stop
            start
            ;;
      condrestart)
            if [ -f ${pidfile} ] ; then
                    stop
                    start
            fi
            ;;
      reload)
            reload
            ;;
      graceful|help|configtest|fullstatus)
            $apachectl $@
            RETVAL=$?
            ;;
      *)
            echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
            exit 1
    esac

    exit $RETVAL



    ]]>
    姣忔棩涓璁?2009/06/11 backup database every day [Script]http://www.tkk7.com/ruoyoux/articles/281466.htmlBlog of JoJoBlog of JoJoThu, 11 Jun 2009 06:17:00 GMThttp://www.tkk7.com/ruoyoux/articles/281466.htmlhttp://www.tkk7.com/ruoyoux/comments/281466.htmlhttp://www.tkk7.com/ruoyoux/articles/281466.html#Feedback0http://www.tkk7.com/ruoyoux/comments/commentRss/281466.htmlhttp://www.tkk7.com/ruoyoux/services/trackbacks/281466.html
    #
    # Created by: JOJO
    # Created Date: 10 June 2009
    # Desc: To backup ps corresponding databases for Point System
    #

    use strict;
    use DateTime;


    main();

    sub main {

          # Get date
        my $dt = DateTime->now;
        my $year   = $dt->year;
          my $month  = sprintf "%02d", $dt->month;
        my $day = sprintf "%02d", $dt->day;
        my $ts = $dt->epoch();


         `mkdir /home/mdrop/PSBackupDB` if (! -d "/home/mdrop/PSBackupDB" );
         `mkdir /home/mdrop/PSBackupDBLog` if (! -d "/home/mdrop/PSBackupDBLog" );
         `mkdir /home/mdrop/PSBackupDB/$year$month` if (! -d "/home/mdrop/PSBackupDB/$year$month" );

          my $dbpath = "/home/mdrop/PSBackupDB";
          my $logpath = "/home/mdrop/PSBackupDBLog";
          my $backlog = "$logpath/backup.log";
          my $user = "root";
          my $pwd = "password";

          #open log file for writing, append purpose
          open(MYLOGFILE, ">>$backlog");


           
          # Export ps db to dump file
          print MYLOGFILE "mysqldump -u$user -p$pwd  pointsystem_sd at $dt"n";
          !`mysqldump -u$user -p$pwd  pointsystem_sd > $dbpath/pointsystem_sd.sql-$year$month$day` || die print "Cannot export pointsystem_sd database."n" >> $backlog;

          print MYLOGFILE "mysqldump -u$user -p$pwd  pointsystem_off at $dt"n";
          !`mysqldump -u$user -p$pwd  pointsystem_off > $dbpath/pointsystem_off.sql-$year$month$day` || die print "Cannot export pointsystem_off database."n" >> $backlog;

          print MYLOGFILE "mysqldump -u$user -p$pwd  pointsys_log_db at $dt"n";
          !`mysqldump -u$user -p$pwd  pointsys_log_db > $dbpath/pointsys_log_db.sql-$year$month$day` || die print "Cannot export pointsys_log_db database."n" >> $backlog;

          print MYLOGFILE "mysqldump -u$user -p$pwd  glassfishtimer at $dt"n";
          !`mysqldump -u$user -p$pwd  glassfishtimer > $dbpath/glassfishtimer.sql-$year$month$day` || die print "Cannot export glassfishtimer database."n" >> $backlog;

          print MYLOGFILE "mysqldump -u$user -p$pwd  obcart at $dt"n";
          !`mysqldump -u$user -p$pwd  obcart > $dbpath/obcart.sql-$year$month$day` || die print "Cannot export obcart database."n" >> $backlog;


          #gzip ps db backup file
          !`cd $dbpath; gzip pointsystem_sd.sql-$year$month$day` || die print "Cannot gzip pointsystem_sd.sql-$year$month$day file."n";
          !`cd $dbpath; gzip pointsystem_off.sql-$year$month$day` || die print "Cannot gzip pointsystem_off.sql-$year$month$day file."n";
          !`cd $dbpath; gzip pointsys_log_db.sql-$year$month$day` || die print "Cannot gzip pointsys_log_db.sql-$year$month$day file."n" ;
          !`cd $dbpath; gzip glassfishtimer.sql-$year$month$day`  || die print "Cannot gzip glassfishtimer.sql-$year$month$day file."n";
          !`cd $dbpath; gzip obcart.sql-$year$month$day`|| die print "Cannot gzip obcart.sql-$year$month$day database."n";

          #move ps db backup sql file to archive folder
          !`mv  $dbpath/pointsystem_sd.sql-$year$month$day.gz $dbpath/$year$month` || die print "Cannot move pointsystem_sd.sql-$year$month$day.gz file."n";
          !`mv  $dbpath/pointsystem_off.sql-$year$month$day.gz $dbpath/$year$month` || die print "Cannot move pointsystem_off.sql-$year$month$day.gz file."n";
          !`mv  $dbpath/pointsys_log_db.sql-$year$month$day.gz $dbpath/$year$month` || die print "Cannot move pointsys_log_db.sql-$year$month$day.gz file."n";
          !`mv  $dbpath/glassfishtimer.sql-$year$month$day.gz $dbpath/$year$month`  || die print "Cannot move glassfishtimer.sql-$year$month$day.gz file."n";
          !`mv  $dbpath/obcart.sql-$year$month$day.gz $dbpath/$year$month`|| die print "Cannot move glassfishtimer.sql-$year$month$day.gz file."n";

    }



    ]]>
    姣忔棩涓璁?2009/06/10 Running Glassfish as a service on CentOShttp://www.tkk7.com/ruoyoux/articles/281155.htmlBlog of JoJoBlog of JoJoWed, 10 Jun 2009 06:39:00 GMThttp://www.tkk7.com/ruoyoux/articles/281155.htmlhttp://www.tkk7.com/ruoyoux/comments/281155.htmlhttp://www.tkk7.com/ruoyoux/articles/281155.html#Feedback0http://www.tkk7.com/ruoyoux/comments/commentRss/281155.htmlhttp://www.tkk7.com/ruoyoux/services/trackbacks/281155.htmlHere is how you run glassfish as a service on CentOS:

    1. Create a user glassfish (you can call it anything you want) under which Glassfish will run.
      #useradd glassfish
    2. Install glassfish in /home/glassfish.
    3. Create the startup script /etc/init.d/glassifsh for glassfish.
                      #!/bin/bash
      #
      # glassfish: Startup script for Glassfish Application Server.
      #
      # chkconfig: 3 80 05
      # description: Startup script for domain1 of Glassfish Application Server.

      GLASSFISH_HOME
      =/home/glassfish/glassfish;
      export GLASSFISH_HOME
      GLASSFISH_OWNER=glassfish;
      export GLASSFISH_OWNER

      start() {
      echo -n "Starting Glassfish: "
      echo "Starting Glassfish at `date`" >> $GLASSFISH_HOME/domains/domain1/logs/startup.log
      su $GLASSFISH_OWNER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1" >> $GLASSFISH_HOME/domains/domain1/logs/startup.log

      sleep 2
      echo "done"
      }

      stop() {
      echo -n "Stopping Glassfish: "
      echo "Stopping Glassfish at `date`" >> $GLASSFISH_HOME/domains/domain1/logs/startup.log
      su $GLASSFISH_OWNER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1" >> $GLASSFISH_HOME/domains/domain1/logs/startup.log
      echo "done"
      }

      # See how we were called.
      case "$1" in
      start)

      start
      ;;

      stop)
      stop
      ;;

      restart)
      stop
      start
      ;;

      *)
      echo $"Usage: glassfish {start|stop|restart}"
      exit
      esac
    4. Install the service
      #chmod +x /etc/init.d/glassfish
      #chkconfig -add glassfish
      #chkconfig --level 3 glassfish on
    5. Start glassfish.
      #/etc/init.d/glassfish start


    ]]>
    姣忔棩涓璁?2009/06/10 Autostarting Glassfish on CentOShttp://www.tkk7.com/ruoyoux/articles/281154.htmlBlog of JoJoBlog of JoJoWed, 10 Jun 2009 06:38:00 GMThttp://www.tkk7.com/ruoyoux/articles/281154.htmlhttp://www.tkk7.com/ruoyoux/comments/281154.htmlhttp://www.tkk7.com/ruoyoux/articles/281154.html#Feedback0http://www.tkk7.com/ruoyoux/comments/commentRss/281154.htmlhttp://www.tkk7.com/ruoyoux/services/trackbacks/281154.html

    I’ve been working with Glassfish recently, from the system administration point of view.  First task, after getting a good build with Maven (doing it with basic rpm methods netted me a massive dependency list, including things like Firefox!), was to write an init script so that Glassfish can be integrated into the CentOS boot sequence.

    Because we might have multiple domains set up inside of Glassfish, I opted for a setup similar to the Tomcat5 init script - check the basename of $0, and use that to determine which domain to boot up.  The fiddling in start() gets around the fact that Glassfish doesn’t seem to write a PID file out where we need one.

    So, just in case anyone else needs to do this:

    #!/bin/bash
    # chkconfig: 2345 85 15
    # description: GlassFish is a Java Application Server.
    # processname: glassfish
    # pidfile: /var/run/glassfish.pid

    # source function library
    . /etc/init.d/functions

    RETVAL=0

    GLASSFISH_BIN="/var/lib/glassfish/bin"

    # Basename works with symbolic links.
    NAME="$(basename $0)"
    unset ISBOOT

    # Trim off the Sxx/Kxx prefix
    if [ "${NAME:0:1}" = "S" -o "${NAME:0:1}" = "K" ]; then
    NAME="${NAME:3}"
    ISBOOT="1"
    fi

    # Trim off the glassfish- prefix
    NAME=${NAME:10}

    # /etc/init.d/glassfish should never be called directly.
    if [ -z $NAME ]; then
    echo -n $"Cannot start Glassfish without specifying a domain."
    failure
    echo
    exit 1
    fi

    start() {

    echo -n $"Starting Glassfish V2 domain $NAME: "
    daemon --user glassfish --pidfile /var/run/glassfish-$NAME.pid "$GLASSFISH_BIN/asadmin start-domain $NAME &gt;/dev/null 2&gt;&amp;1"
    RETVAL=$?

    if [ $RETVAL -eq 0 ]; then
    PID=`ps U glassfish | grep $NAME | awk '{ print $1}'`
    echo $PID &gt; /var/run/glassfish-$NAME.pid
    touch /var/lock/subsys/glassfish-$NAME
    fi

    echo
    }


    stop() {

    echo -n $"Shutting down Glassfish V2 domain $NAME: "

    $GLASSFISH_BIN/asadmin stop-domain $NAME &gt;/dev/null 2&gt;&amp;1

    RETVAL=$?

    [ $RETVAL -eq 0 ] &amp;&amp; rm -f /var/lock/subsys/glassfish-$NAME &amp;&amp; rm -f /var/run/glassfish-$NAME &amp;&amp; success || failure

    echo

    }

    case "$1" in

    start)

    start

    ;;

    stop)

    stop
    ;;

    restart|reload)

    stop

    start

    ;;

    condrestart)

    if [ -f /var/lock/subsys/glassfish-$NAME ]; then

    stop

    start
    fi
    ;;

    status)
    status glassfish-$NAME

    RETVAL=$?
    ;;

    *)

    echo $"Usage: $0 {start|stop|restart|condrestart|status}"

    exit 1

    esac

    exit $RETVAL

    The alternative is to define a /etc/sysconfig/glassfish file, and insert a variable with the list of domains to boot, in sequence.  This is a little harder to manage automatically in Puppet, but might be a better solution if precise boot sequences are required (this method will boot in sequence based on the S numbers in the base script, and then the alphabetical ordering of the names).



    ]]>
    主站蜘蛛池模板: 亚洲国产AV一区二区三区四区| 久久夜色精品国产亚洲av| 国产精彩免费视频| 91精品国产免费久久国语蜜臀| 国产免费拔擦拔擦8X高清在线人 | 亚洲Av无码专区国产乱码DVD| 亚洲宅男天堂在线观看无病毒| 久久久久久亚洲精品不卡| 亚洲精品在线视频| 亚洲熟妇丰满多毛XXXX| 亚洲va久久久噜噜噜久久狠狠| 久久精品国产96精品亚洲 | 久久精品国产亚洲AV网站| 亚洲日韩区在线电影| 亚洲理论片中文字幕电影| 亚洲AV色吊丝无码| 亚洲国产欧洲综合997久久| 国产亚洲蜜芽精品久久| 亚洲视频在线免费| 在线看片免费人成视频播| 在线看片免费人成视久网| 无码少妇一区二区浪潮免费| 日韩在线天堂免费观看| 亚洲高清国产拍精品青青草原| 中文字幕亚洲日韩无线码| 亚洲另类激情综合偷自拍| 亚洲av无码国产综合专区| 亚洲国产精品久久久久秋霞小| 深夜特黄a级毛片免费播放| 国产自国产自愉自愉免费24区 | 成人AV免费网址在线观看| 日本免费福利视频| 国产中文在线亚洲精品官网| 亚洲VA成无码人在线观看天堂| 亚洲冬月枫中文字幕在线看| mm1313亚洲国产精品无码试看| 久久久久久av无码免费看大片| 中文字幕在线观看免费视频| 欧洲精品免费一区二区三区| 国产国拍精品亚洲AV片| 亚洲二区在线视频|