﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-jojo's blog－－快乐忧伤都与你同在-文章分类-My Script</title><link>http://www.blogjava.net/ruoyoux/category/40789.html</link><description>为梦想而来，为自由而生。
性情若水，风起水兴，风息水止，故时而激荡，时又清平……</description><language>zh-cn</language><lastBuildDate>Fri, 07 Aug 2009 08:52:41 GMT</lastBuildDate><pubDate>Fri, 07 Aug 2009 08:52:41 GMT</pubDate><ttl>60</ttl><item><title>每日一记 2009/08/06 perl socket script </title><link>http://www.blogjava.net/ruoyoux/articles/290071.html</link><dc:creator>Blog of JoJo</dc:creator><author>Blog of JoJo</author><pubDate>Thu, 06 Aug 2009 04:11:00 GMT</pubDate><guid>http://www.blogjava.net/ruoyoux/articles/290071.html</guid><wfw:comment>http://www.blogjava.net/ruoyoux/comments/290071.html</wfw:comment><comments>http://www.blogjava.net/ruoyoux/articles/290071.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruoyoux/comments/commentRss/290071.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruoyoux/services/trackbacks/290071.html</trackback:ping><description><![CDATA[Here is the script in it's<br />
entirety.<br />
It would be taylored to only execute one<br />
command not an open perl script. Better<br />
than having root .rhosts everywhere.<br />
I think where it does the:<br />
<br />
print F $Line;<br />
<br />
at the bottom is where I could put some<br />
kind of execute statement.<br />
Take the string and run it not print it<br />
to a file.<br />
<br />
<br />
<br />
socket.client.perl<br />
#!/usr/bin/perl<br />
#===============================================<br />
# Client -- using object interface<br />
# Support Windows and UNIX<br />
#===============================================<br />
use IO::Socket;<br />
my $sock = new IO::Socket::INET (<br />
PeerAddr =&gt; '128.166.11.13',<br />
PeerPort =&gt; '9999',<br />
Proto =&gt; 'tcp',<br />
);<br />
die "Could not create socket: $!"n" unless $sock;<br />
print $sock "Hi there!"n";<br />
$sock-&gt;send("Hi again!"n");<br />
<br />
close($sock);<br />
<br />
<br />
socket.server.perl<br />
#!/usr/bin/perl<br />
#===============================================<br />
# Server -- using object interface<br />
# Support Windows and UNIX<br />
#===============================================<br />
<br />
#use Proc::Daemon;<br />
use IO::Socket;<br />
#Proc::Daemon::Init();<br />
<br />
use POSIX qw(setsid);<br />
<br />
sub daemonize {<br />
die "Can't fork" unless defined (my $child = fork());<br />
exit 0 if $child;<br />
setsid();<br />
open(STDIN, "&lt;/dev/null");<br />
open(STDOUT, "&gt;/dev/null");<br />
open(STDERR, "&gt;&amp;STDOUT");<br />
chdir '/';<br />
umask(0);<br />
#$ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin';<br />
return $$;<br />
};<br />
<br />
&amp;daemonize;<br />
while() {<br />
my $new_sock = $sock-&gt;accept();<br />
<br />
####################################<br />
# Put a message to file. #<br />
####################################<br />
<br />
while(defined($Line = &lt;$new_sock&gt;)) {<br />
open (F,"+&gt;&gt;/lhome/root/testfile.txt");<br />
print F $Line;<br />
close F;<br />
};<br />
close($sock);<br />
}; #End of while cycle<br />
A. Clay Stephenson Expert in this area This member has accumulated 80000 or more points &nbsp;&nbsp; &nbsp;<br />
May 21, 2004 16:47:45 GMT&nbsp; 10 pts &nbsp;&nbsp; &nbsp;<br />
In that case, $Line has your input so you can use it to execute whatever you like.<br />
<br />
Typically, your client should send a formatted request string of some type. I like to use &lt;tabs&gt; to separate the fields and then your server responds each time it sees a new line of input.<br />
<br />
<br />
<br />
------------------------------------------------------------------------------------------------------<br />
<br />
<span>All I am saying in that any client/server architecture, you must establish some sort of protocol.<br />
<br />
Let's suppose that your server does 4 things:<br />
1) lists files in a dedicated directories<br />
2) removes 1 file<br />
3) add's a line to an existing file<br />
4) kill the server<br />
<br />
Your create client requests that adhere to this, for example, you formant your protocol like this<br />
request_code&lt;tab&gt;string1&lt;tab&gt;string2&lt;LF&gt;<br />
<br />
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<br />
<br />
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.<br />
<br />
-----------------------------------------------------------------------------------------------<br />
<br />
</span>For now though. I just wanted something<br />
simple to get around the root .rhosts problem. I was thinking as a security measure<br />
of passing a code to the server.pl but don't<br />
know the perl syntax at this time.<br />
Could you show me the simple syntax for<br />
passing two args.<br />
<br />
e.g.<br />
<br />
From client.pl send:<br />
<br />
1234  shutdown.sh<br />
<br />
On server.pl check code then run command:<br />
<br />
1234 shutdown.sh<br />
<br />
<br />
On my client.perl I currently have:<br />
<br />
print $sock "shutdown.sh"<br />
<br />
On my server.perl I have:<br />
<br />
while(defined($Line = &lt;$new_sock&gt;)) {<br />
system($Line);<br />
close($sock);<br />
};  #End <br />
<br />
<img src ="http://www.blogjava.net/ruoyoux/aggbug/290071.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruoyoux/" target="_blank">Blog of JoJo</a> 2009-08-06 12:11 <a href="http://www.blogjava.net/ruoyoux/articles/290071.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>每日一记 2009/08/06 use ssh to execute perl script remotely</title><link>http://www.blogjava.net/ruoyoux/articles/290070.html</link><dc:creator>Blog of JoJo</dc:creator><author>Blog of JoJo</author><pubDate>Thu, 06 Aug 2009 04:08:00 GMT</pubDate><guid>http://www.blogjava.net/ruoyoux/articles/290070.html</guid><wfw:comment>http://www.blogjava.net/ruoyoux/comments/290070.html</wfw:comment><comments>http://www.blogjava.net/ruoyoux/articles/290070.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruoyoux/comments/commentRss/290070.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruoyoux/services/trackbacks/290070.html</trackback:ping><description><![CDATA[<pre>#!/opt/TLCLperl/bin/perl -w<br />
#!/usr/local/bin/perl -w<br />
<br />
#<br />
# use ssh to execute perl script remotely<br />
#<br />
<br />
# You can change PERL and REMOTE_CMD constants to reflect your real<br />
# environment...<br />
<br />
use constant PERL =&gt; 'perl'; # maybe "/usr/local/bin/perl"<br />
use constant REMOTE_CMD =&gt; 'ssh';<br />
use constant CAT_CMD =&gt; 'cat';<br />
<br />
use strict;<br />
use vars qw($VERSION);<br />
$VERSION = '1.00';<br />
<br />
use constant USAGE =&gt; &lt;&lt;EOU;<br />
<br />
Usage:<br />
<br />
$0 ""<br />
[-v]                                 ""<br />
[-r&lt;remote command flags&gt;]           ""<br />
[-R&lt;remote command&gt;]                 ""<br />
[-Q&lt;perl path&gt;]                      ""<br />
[&lt;usual perl flags&gt;]                 ""<br />
&lt;[&lt;remote user&gt;@]remote_host&gt;[,...]  ""<br />
[&lt;local_script.pl | -e 'perl code'&gt;] ""<br />
[&lt;script args&gt;]<br />
<br />
EOU<br />
<br />
# options for command line parsing<br />
my $verbose; # -v<br />
my @remote_opts; # opts for ssh/remote command<br />
my $remote_cmd; # ssh substitute<br />
my @perl_opts; # opts for remote perl<br />
my $perl_cmd; # remote perl path<br />
<br />
# extract options. This is very simple parsing of options and force<br />
# the args to be precisely ordered.<br />
while(defined $ARGV[0] and $ARGV[0]=~/^-/) {<br />
$_=shift;<br />
if    (/^-v/)     { $verbose=1 }<br />
elsif (/^-r(.*)/) { push @remote_opts,$1 }<br />
elsif (/^-R(.*)/) { $remote_cmd=$1 }<br />
elsif (/^-Q(.*)/) { $perl_cmd=$1 }<br />
else { push @perl_opts,"'$_'" }<br />
}<br />
<br />
# use the default REMOTE_CMD<br />
$remote_cmd||=REMOTE_CMD;<br />
<br />
# read remote machine name:<br />
my $machines=shift or die "error: remote machine not specified"n".USAGE;<br />
my @machines=split(',',$machines);<br />
<br />
# script name... when available:<br />
my $file=shift;<br />
<br />
# get the perl code to run remotely:<br />
my $code;<br />
if(defined $file and $file eq '-e') {<br />
# perl code is in cmd line after the -e switch.<br />
$code=shift or die "error: no perl code after '-e'"n".USAGE;<br />
}<br />
else {<br />
if (defined $file) {<br />
if($file=~/(.+):(.+)/) {<br />
# read perl code from remote file<br />
open(F,"$remote_cmd '$1' ".CAT_CMD." '$2'|")<br />
or die "error: unable to read remote file '$2' from '$1' ($!)"n";<br />
}<br />
else {<br />
# read perl code from file.<br />
open(F,"&lt; $file")<br />
or die "error: unable to open '$file' ($!)"n";<br />
}<br />
}<br />
else { *F=*STDIN } # read perl code from stdin<br />
{<br />
# slurp the file to $code<br />
local $/=undef;<br />
$code=&lt;F&gt;;<br />
}<br />
# gets perl path and flags for first line in src file if available:<br />
if ($code=~/"A"#!(.*)$/m) {<br />
my $line=$1;<br />
if ($line=~/"s*("S+)"s*(.*)/) {<br />
$perl_cmd||=$1;<br />
# anything in the line after the perl path will be considered to<br />
# be flags. I know this could be improved.<br />
push @perl_opts,$2 if defined $2;<br />
}<br />
}<br />
}<br />
<br />
# use the default PERL location if it is yet unknow<br />
$perl_cmd||=PERL;<br />
<br />
# convert code to hex string<br />
my $packed = unpack "h*",$code;<br />
<br />
# this is the remote program to decode and run the script:<br />
my $decoder = q{'BEGIN{eval"sub _R{".(pack"h*",shift)."}"}_R(@ARGV)'};<br />
# There was a simpler decoder but it didn't works with the -n flag so<br />
# I have changed it...<br />
# my $decoder = q{'eval pack"h*",shift'};<br />
<br />
# format script args with "'" between them:.<br />
my $args='';<br />
{<br />
local $"="' '";<br />
$args="'@ARGV'" if @ARGV;<br />
}<br />
<br />
foreach my $machine (@machines) {<br />
# complete ssh cmd. Remote command is escaped.<br />
my $cmd="$remote_cmd @remote_opts $machine ".<br />
quotemeta "$perl_cmd @perl_opts -e $decoder $packed $args";<br />
<br />
# print cmd if verbosity enabled<br />
print STDERR "remote cmd:"n$cmd"n"n" if $verbose;<br />
<br />
# run it and report problems<br />
system($cmd)<br />
and print STDERR "Unable to exec ($!)."nRemote command was:"n$cmd"n"n";<br />
}<br />
<br />
#################################################<br />
# documentation:<br />
<br />
<br />
=head1 NAME<br />
<br />
sperl - runs perl scripts in remote machines through ssh<br />
<br />
<br />
=head1 SCRIPT CATEGORIES<br />
<br />
Networking<br />
UNIX/System_administration<br />
Perl/Utilities<br />
<br />
<br />
=head1 README<br />
<br />
sperl is some kind of enhanced perl that lets you work in a network<br />
environment and run scripts and oneliners in remote machines without<br />
the need to <br />
<br />
<br />
=head1 USAGE<br />
<br />
$ sperl "<br />
[-v]                                                "<br />
[-r&lt;remote command flags&gt;]                          "<br />
[-R&lt;remote command&gt;]                                "<br />
[-Q&lt;perl path&gt;]                                     "<br />
[&lt;usual perl flags&gt;]                                "<br />
&lt;[&lt;remote user&gt;@]remote_host&gt;[,...]                 "<br />
[&lt;[&lt;[&lt;user&gt;@]machine&gt;:]script.pl | -e 'perl code'&gt;] "<br />
[&lt;script args&gt;]<br />
<br />
<br />
=head1 INSTALLATION<br />
<br />
To install sperl, copy it to some place in your path like<br />
/usr/local/bin/sperl and allow execution of it with C&lt;chmod 755<br />
/your/path/to/sperl&gt;.<br />
<br />
If you want, you can edit the script and change the PERL and<br />
REMOTE_CMD constants at the beginning to match your real environment.<br />
<br />
<br />
=head1 DESCRIPTION<br />
<br />
C&lt;sperl&gt; lets you run a locally stored perl script in a remote machine<br />
for which ssh (or equivalent) access is available.<br />
<br />
It doesn't need any special module installed in local or remote<br />
machines, just plain perl.<br />
<br />
If there isn't script name in the command line, neither C&lt;-e&gt; option,<br />
sperl will try to read the code form stdin as perl use to do.<br />
<br />
It's possible to take the script file from another remote machine<br />
with the syntax C&lt;machine:/path/to/script.pl&gt; or even<br />
C&lt;user@machine:/path/to/script.pl&gt;.<br />
<br />
It's also possible to include several remote host names separated by<br />
commas and the script will be run in all of them. For example C&lt;hippo,bugs,bill@www.microsoft.com&gt;<br />
<br />
<br />
=head1 OPTIONS<br />
<br />
C&lt;sperl&gt; accepts the same command line options as C&lt;perl&gt; does. The<br />
options are passed unchanged to the remote perl interpreter so some of<br />
them like C&lt;-S&gt; are nonsense.<br />
<br />
Additionally, it accepts some specific options:<br />
<br />
=over<br />
<br />
=item -rE&lt;lt&gt;remote command flagsE&lt;gt&gt;<br />
<br />
pass options to ssh. For instance C&lt;-r-v&gt;<br />
<br />
=item -RE&lt;lt&gt;remote commandE&lt;gt&gt;<br />
<br />
specify the command to use in place of ssh to connect to the remote<br />
machine. for instance C&lt;-Rrsh&gt;.<br />
<br />
=item -QE&lt;lt&gt;remote perl pathE&lt;gt&gt;<br />
<br />
specify the location of the perl interpreter in the remote<br />
machine. By default, sperl will try to look for the perl path in the<br />
script first line, if it uses the notation C&lt;#!/path/to/perl&gt;. As its<br />
last resource it expects perl to be in the PATH.<br />
<br />
=item -v<br />
<br />
dumps the remote command to stderr before running it. This is primary<br />
for debugging purposes.<br />
<br />
=back<br />
<br />
<br />
=head1 EXAMPLES<br />
<br />
[salvador@hippo:~]$ sperl admin@willy "<br />
&gt; -e 'print "hello from ".`hostname`'<br />
hello from willy<br />
<br />
# the -t option force ssh to allocate a new tty...<br />
[salvador@hippo:~]$ sperl -w -r-t willy -e 'print $count+1,""n"'<br />
Use of uninitialized value at (eval 1) line 1.<br />
1<br />
<br />
# you can even invoke the perl debugger remotely:<br />
[salvador@hippo:~]$ sperl -d -r-t willy -e 1<br />
<br />
Loading DB routines from perl5db.pl version 1.0401<br />
Emacs support available.<br />
<br />
Enter h or `h h' for help.<br />
<br />
main::(-e:1):   BEGIN{eval"sub _R{".(pack"h*",shift)."}"}_R(@ARGV)<br />
DB&lt;1&gt; p `hostname`<br />
p `hostname`<br />
willy<br />
<br />
DB&lt;2&gt; ...<br />
<br />
# running the same code in several machines:<br />
[salvador@hippo:~]$ sperl bugs,willy,hippo -e "<br />
&gt; 'chomp($h=`hostname`);print "hello from $h!!!"n"'<br />
hello from bugs!!!<br />
hello from willy!!!<br />
hello from hippo!!!<br />
<br />
<br />
<br />
=head1 CHANGES<br />
<br />
=over<br />
<br />
=item sperl 1.00     Thu Sep 23 1999<br />
<br />
First public release<br />
<br />
=back<br />
<br />
<br />
=head1 BUGS AND LIMITATIONS<br />
<br />
This is a beta release so expect errors in it.<br />
<br />
Lots of spelling errors in the docs... Help me!!!<br />
<br />
The order of the options in the command line is very inflexible.<br />
<br />
Switch parsing for the first line of the script is not very clever and<br />
it will produce unexpected results if something complex is there.<br />
<br />
Scripts with C&lt;__END__&gt; or C&lt;__DATA__&gt; sections will fail.<br />
<br />
I don't know if there is any possibility to make this to work in<br />
Microsoft's world.<br />
<br />
<br />
=head1 AUTHOR<br />
<br />
Salvador Fandi&#241;o Garc&#237;a &lt;salvador@cesat.es, fandino@usa.net&gt;<br />
<br />
<br />
=head1 SEE ALSO<br />
<br />
L&lt;perl(1)&gt;, L&lt;ssh(1)&gt; or L&lt;rsh(1)&gt;, L&lt;perlrun(1)&gt;.<br />
<br />
<br />
=cut <br />
</pre>
<img src ="http://www.blogjava.net/ruoyoux/aggbug/290070.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruoyoux/" target="_blank">Blog of JoJo</a> 2009-08-06 12:08 <a href="http://www.blogjava.net/ruoyoux/articles/290070.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>每日一记 2009/08/06 How to execute a perl script at remote server [My problem]</title><link>http://www.blogjava.net/ruoyoux/articles/290069.html</link><dc:creator>Blog of JoJo</dc:creator><author>Blog of JoJo</author><pubDate>Thu, 06 Aug 2009 04:06:00 GMT</pubDate><guid>http://www.blogjava.net/ruoyoux/articles/290069.html</guid><wfw:comment>http://www.blogjava.net/ruoyoux/comments/290069.html</wfw:comment><comments>http://www.blogjava.net/ruoyoux/articles/290069.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruoyoux/comments/commentRss/290069.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruoyoux/services/trackbacks/290069.html</trackback:ping><description><![CDATA[Hi All,<br />
&nbsp; &nbsp;<br />
&nbsp;&nbsp;&nbsp; I have written a Perl script, which deals with the ftp ing<br />
(transferring) the file to remote server and executing a Perl script<br />
(AUT) at remote m/c.<br />
<br />
The script is as below and here I have 2 doubts, so please help me to<br />
resolve this.<br />
1) I am getting the message like "could not transfer the file to<br />
server" but it is ftp ing the flie to remote m/c, and I can see that<br />
file ( root1.txt ) there.<br />
<br />
2) And I want to run the perl script (AUT) at remote m/c depending<br />
on the data we sent, so could you please let me know how can I achieve<br />
this.<br />
<br />
Is it possible for me to do system("test.pl"),&nbsp; If I am at SFTP mode.<br />
Please see comment line in the code below.<br />
<br />
<br />
<br />
#!/usr/bin/perl -w<br />
<br />
use strict;<br />
use warnings;<br />
use Net::SFTP;<br />
<br />
my $server="A.BY.C.D";<br />
my $user="roserag";<br />
my $password="june@123";<br />
my %args = (user =&gt; "$user", password =&gt; "$password", ssh_args =&gt; []);<br />
$args{debug} = 1;<br />
$args{user} = "root";<br />
my $file="local.txt";<br />
my $rfile = "root1.txt";<br />
<br />
my $sftp=Net::SFTP-&gt;new($server, %args) or die "could not open<br />
connection to $server"n";<br />
$sftp-&gt;put($file,$rfile) or die " could not transfer the file to server<br />
"n";<br />
<br />
<br />
# system("test.pl");&nbsp;&nbsp;&nbsp; Is this command work out.<br />
<br />
exit;<br />
<br />
<br />
[gaurav@testbrix Examples]$ perl sftp3.pl<br />
testbrix.wipro.com: Reading configuration data /home/gaurav/.ssh/config<br />
testbrix.wipro.com: Reading configuration data /etc/ssh_config<br />
...................................<br />
...................................<br />
testbrix.wipro.com: sftp: In write loop, got 510 offset 0<br />
testbrix.wipro.com: sftp: Sent message T:10 I:2<br />
testbrix.wipro.com: sftp: Sent message T:4 I:3<br />
could not transfer the file to server<br />
<br />
But I can see the file the file at server.<br />
<br />
<br />
Regards,<br />
XXX<br />
<br />
<br />
Please do not print this email unless it is absolutely necessary. <br />
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. <br />
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. <br />
<br />
www.wipro.com<br />
<br />
<img src ="http://www.blogjava.net/ruoyoux/aggbug/290069.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruoyoux/" target="_blank">Blog of JoJo</a> 2009-08-06 12:06 <a href="http://www.blogjava.net/ruoyoux/articles/290069.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>每日一记 2009/07/31 Create Glassfish Cluster in Windowns</title><link>http://www.blogjava.net/ruoyoux/articles/289240.html</link><dc:creator>Blog of JoJo</dc:creator><author>Blog of JoJo</author><pubDate>Fri, 31 Jul 2009 03:55:00 GMT</pubDate><guid>http://www.blogjava.net/ruoyoux/articles/289240.html</guid><wfw:comment>http://www.blogjava.net/ruoyoux/comments/289240.html</wfw:comment><comments>http://www.blogjava.net/ruoyoux/articles/289240.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruoyoux/comments/commentRss/289240.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruoyoux/services/trackbacks/289240.html</trackback:ping><description><![CDATA[[mdrop@deployment1-1 newDeploy]$ cat config-new-environment.bat <br />
@echo off<br />
<br />
set DOMAIN=domain1<br />
set CLUSTER=server<br />
<br />
<br />
set MASTERIP=127.0.0.1<br />
set NODE1=agent1<br />
<br />
set INSTANCE1=ps1<br />
set NODE2=agent2<br />
set INSTANCE2=ps2<br />
<br />
if "%1" == "" goto :ERROR<br />
<br />
if "%2" == "" goto :ERROR<br />
<br />
call %1"bin"asadmin stop-domain domain1<br />
<br />
xcopy classes"*.* /s %1"domains"domain1"lib"classes<br />
copy mysql-connector-java-5.1.5-bin.jar %1"domains"domain1"lib"ext<br />
<br />
call %1"bin"asadmin start-domain domain1<br />
<br />
call %1"bin"asadmin set server.java-config.classpath-suffix=%1"domains"domain1"lib"ext"mysql-connector-java-5.1.5-bin.jar<br />
call %1"bin"asadmin set server.java-config.classpath-suffix=${com.sun.aas.instanceRoot}/lib/classes<br />
call %1"bin"asadmin set server.system-property.com_outblaze_config_cobrand="C:"config"<br />
<br />
call %1"bin"asadmin create-auth-realm --classname com.outblaze.glassfish.security.OBAppservRealm --property auth-type=obRealm:jaas-context=obRealm --target server obRealm<br />
<br />
echo obRealm {com.outblaze.glassfish.security.OBPasswordLoginModule required;}; &gt;&gt; %1"domains"domain1"config"login.conf<br />
<br />
<br />
<br />
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<br />
<br />
call %1"bin"asadmin create-jdbc-resource --connectionpoolid mysqlPool --target server jndi/cobrandpsDS<br />
<br />
call %1"bin"asadmin delete-jdbc-connection-pool --cascade=true --target server mysqlPoolOffline<br />
<br />
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<br />
<br />
call %1"bin"asadmin create-jdbc-resource --connectionpoolid mysqlPoolOffline --target server jndi/cobrandpsDS_of<br />
<br />
call %1"bin"asadmin delete-jdbc-connection-pool --cascade=true --target server mysqlPoolLog<br />
<br />
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<br />
<br />
call %1"bin"asadmin create-jdbc-resource --connectionpoolid mysqlPoolLog --target server jndi/cobrandpsDS_log<br />
<br />
call %1"bin"asadmin delete-jdbc-connection-pool --cascade=true --target server itemmallsqlPool<br />
<br />
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<br />
<br />
call %1"bin"asadmin create-jdbc-resource --connectionpoolid itemmallsqlPool --target server jndi/itemmallDS<br />
<br />
call %1"bin"asadmin delete-jdbc-connection-pool --cascade=true --target server mysqlPoolpsClusterTimer<br />
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<br />
call %1"bin"asadmin create-jdbc-resource --connectionpoolid mysqlPoolpsClusterTimer --target server jndi/ps_cluster_timer<br />
call %1"bin"asadmin set --user admin --port 4848 server-config.ejb-container.ejb-timer-service.timer-datasource=jndi/ps_cluster_timer<br />
<br />
<br />
echo prepare for MQ<br />
echo =============================================================================<br />
call %1"bin"asadmin delete-jmsdest&nbsp; --desttype queue --target server ActiveMqQueue<br />
call %1"bin"asadmin delete-admin-object --target server jms/ActiveMqQueue<br />
call %1"bin"asadmin delete-connector-resource --target server jms/ActiveMQConnectionFactory<br />
call %1"bin"asadmin delete-connector-connection-pool --target server jms/ActiveMQpool<br />
call %1"bin"asadmin undeploy --target server activemq-rar-5.1.0<br />
echo finished prepare for MQ<br />
echo =============================================================================<br />
<br />
echo start config for MQ<br />
echo --------------------------------------------------------------------------------<br />
XCOPY activeMQ_config"bin"*.* %2"bin" /k /y /z<br />
XCOPY activeMQ_config"conf"*.* %2"conf /k /y /z<br />
XCOPY activeMQ_config"webapps"admin"*.* %2"webapps"admin" /k /y /z<br />
XCOPY activeMQ_config"webapps"admin"decorators"*.* %2"webapps"admin"decorators" /k /y /z<br />
XCOPY activeMQ_config"webapps"admin"WEB-INF"*.* %2"webapps"admin"WEB-INF" /k /y /z<br />
<br />
<br />
call %1"bin"asadmin deploy --user admin --host localhost --port 4848 --target server activemq-rar-5.1.0.rar<br />
echo finished deploying activemq-rar-5.1.0.rar<br />
<br />
call %1"bin"asadmin create-admin-object --raname activemq-rar-5.1.0 --restype javax.jms.Queue --property DestinationJndiName=ActiveMqQueue --target server jms/ActiveMqQueue<br />
echo finished create admin object jms/ActiveMqQueue<br />
<br />
call %1"bin"asadmin create-jmsdest --desttype queue --target server ActiveMqQueue<br />
echo finished create jmsdest ActiveMqQueue<br />
<br />
call %1"bin"asadmin create-connector-connection-pool --raname activemq-rar-5.1.0 --connectiondefinition javax.jms.ConnectionFactory --transactionsupport&nbsp; XATransaction --target server jms/ActiveMQpool<br />
echo finished create connector connection pool jms/ActiveMQpool<br />
<br />
call %1"bin"asadmin create-connector-resource --poolname jms/ActiveMQpool --target server jms/ActiveMQConnectionFactory<br />
echo finished create connector resource jms/ActiveMQConnectionFactory<br />
<br />
echo MQ Setup complete<br />
echo --------------------------------------------------------------------------------<br />
<br />
echo Shutting down Glassfish<br />
call %1"bin"asadmin stop-domain domain1<br />
<br />
echo Setup complete<br />
goto :END<br />
<br />
<br />
:ERROR<br />
echo Please set glassfish base path and activeMQ path.<br />
echo e.g. config-new-glassfish c:"glassfish c:"apache-activemq-5.1.0-bin<br />
<br />
:END
<img src ="http://www.blogjava.net/ruoyoux/aggbug/289240.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruoyoux/" target="_blank">Blog of JoJo</a> 2009-07-31 11:55 <a href="http://www.blogjava.net/ruoyoux/articles/289240.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>每日一记 2009/07/31 Set Up Glassfish Cluster &amp; Config Sql Connection in Linux</title><link>http://www.blogjava.net/ruoyoux/articles/289239.html</link><dc:creator>Blog of JoJo</dc:creator><author>Blog of JoJo</author><pubDate>Fri, 31 Jul 2009 03:53:00 GMT</pubDate><guid>http://www.blogjava.net/ruoyoux/articles/289239.html</guid><wfw:comment>http://www.blogjava.net/ruoyoux/comments/289239.html</wfw:comment><comments>http://www.blogjava.net/ruoyoux/articles/289239.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruoyoux/comments/commentRss/289239.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruoyoux/services/trackbacks/289239.html</trackback:ping><description><![CDATA[[mdrop@deployment1-1 newDeploy]$ cat setup_gf.sh <br />
#!/bin/bash<br />
<br />
# Do not edit below , please supply variable in command line<br />
ACTION=$1<br />
COBRAND=$2<br />
GLASS_FISH=$3<br />
DOMAIN=domain1<br />
MASTERIP=$4<br />
ACTIVEMQ=$5<br />
INSTANCE_NO=$6<br />
JDBC_USER=$7<br />
JDBC_PASSWORD=$8<br />
JDBC_HOST=$9<br />
<br />
<br />
<br />
CLUSTER=ps-$COBRAND-cluster<br />
NODE=ps-$COBRAND-node-$INSTANCE_NO<br />
INSTANCE=ps-$COBRAND-instance-$INSTANCE_NO<br />
<br />
<br />
function common () {<br />
<br />
<br />
#those two command should be executed in master and slave machine<br />
cp mysql-connector-java-5.1.5-bin.jar $GLASS_FISH/lib<br />
cp obrealm.jar&nbsp; $GLASS_FISH/lib<br />
cp -rf activeMQ_config/*&nbsp; $ACTIVEMQ/<br />
<br />
if [ $ACTION = "master" ]; then<br />
$GLASS_FISH/bin/asadmin stop-domain $DOMAIN<br />
$GLASS_FISH/bin/asadmin start-domain $DOMAIN<br />
fi<br />
<br />
#run those following lines to stop cluster and node in the master machine<br />
if [ $ACTION = "master" ]; then<br />
$GLASS_FISH/bin/asadmin stop-cluster --user admin --host&nbsp; $MASTERIP&nbsp; --port 4848 $CLUSTER<br />
fi<br />
$GLASS_FISH/bin/asadmin stop-node-agent $NODE<br />
<br />
#run those following lines to delete node, cluster and instance in the master machine<br />
$GLASS_FISH/bin/asadmin delete-node-agent&nbsp; $NODE<br />
if [ $ACTION = "master" ]; then<br />
$GLASS_FISH/bin/asadmin delete-cluster&nbsp; $CLUSTER<br />
fi<br />
$GLASS_FISH/bin/asadmin delete-instance&nbsp; $INSTANCE<br />
<br />
<br />
#run those following lines to create node, cluster and instance in the master machine<br />
$GLASS_FISH/bin/asadmin create-node-agent --host $MASTERIP --port 4848 $NODE<br />
if [ $ACTION = "master" ]; then<br />
$GLASS_FISH/bin/asadmin create-cluster --host $MASTERIP --port 4848 $CLUSTER<br />
fi<br />
$GLASS_FISH/bin/asadmin create-instance --host $MASTERIP --port 4848 --nodeagent $NODE --cluster $CLUSTER $INSTANCE<br />
<br />
<br />
<br />
#run those following lines to start node, cluster and instance in the master machine<br />
#bin/asadmin start-node-agent --syncinstances=true $NODE<br />
#bin/asadmin start-cluster --user admin --host $MASTERIP --port 4848 $CLUSTER<br />
#bin/asadmin start-instance --user admin --host $MASTERIP --port 4848 $INSTANCE<br />
<br />
}<br />
<br />
function master () {<br />
<br />
#cp -r classes/* $GLASS_FISH/domains/$DOMAIN/lib/classes/<br />
<br />
cp&nbsp; activemq-rar-5.1.0.rar&nbsp; $GLASS_FISH/<br />
<br />
#those two command should be executed in master and slave machine<br />
cp mysql-connector-java-5.1.5-bin.jar $GLASS_FISH/lib<br />
cp obrealm.jar&nbsp; $GLASS_FISH/lib<br />
<br />
$GLASS_FISH/bin/asadmin stop-domain $DOMAIN<br />
$GLASS_FISH/bin/asadmin start-domain $DOMAIN<br />
<br />
<br />
<br />
$GLASS_FISH/bin/asadmin set $CLUSTER.java-config.classpath-suffix='${com.sun.aas.installRoot}/lib/mysql-connector-java-5.1.5-bin.jar'<br />
$GLASS_FISH/bin/asadmin set $CLUSTER.java-config.classpath-suffix='${com.sun.aas.installRoot}/lib/obrealm.jar'<br />
mkdir -p /usr/local/site/webroot/template/pointsystem/<br />
$GLASS_FISH/bin/asadmin set $CLUSTER.system-property.com_outblaze_config_cobrand='/usr/local/site/webroot/template/pointsystem/'<br />
$GLASS_FISH/bin/asadmin create-auth-realm --classname com.outblaze.glassfish.security.OBAppservRealm --property auth-type=obRealm:jaas-context=obRealm --target $CLUSTER obRealm<br />
<br />
echo "obRealm {com.outblaze.glassfish.security.OBPasswordLoginModule required;};" &gt;&gt; $GLASS_FISH/domains/$DOMAIN/config/login.conf<br />
<br />
$GLASS_FISH/bin/asadmin&nbsp; set $CLUSTER.http-service.virtual-server.server.property.accessLoggingEnabled=true<br />
echo "finished setting the access log "<br />
<br />
$GLASS_FISH/bin/asadmin delete-jdbc-connection-pool --cascade=true --target $CLUSTER mysqlPool<br />
$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<br />
$GLASS_FISH/bin/asadmin create-jdbc-resource --connectionpoolid mysqlPool --target $CLUSTER jndi/cobrandpsDS<br />
$GLASS_FISH/bin/asadmin delete-jdbc-connection-pool --cascade=true --target $CLUSTER mysqlPoolOffline<br />
$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<br />
$GLASS_FISH/bin/asadmin create-jdbc-resource --connectionpoolid mysqlPoolOffline --target $CLUSTER jndi/cobrandpsDS_of<br />
$GLASS_FISH/bin/asadmin delete-jdbc-connection-pool --cascade=true --target $CLUSTER mysqlPoolLog<br />
$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<br />
$GLASS_FISH/bin/asadmin create-jdbc-resource --connectionpoolid mysqlPoolLog --target $CLUSTER jndi/cobrandpsDS_log<br />
$GLASS_FISH/bin/asadmin delete-jdbc-connection-pool --cascade=true --target $CLUSTER itemmallsqlPool<br />
$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<br />
$GLASS_FISH/bin/asadmin create-jdbc-resource --connectionpoolid itemmallsqlPool --target $CLUSTER jndi/itemmallDS<br />
<br />
$GLASS_FISH/bin/asadmin delete-jdbc-connection-pool --cascade=true --target $CLUSTER mysqlPoolpsClusterTimer<br />
$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<br />
$GLASS_FISH/bin/asadmin create-jdbc-resource --connectionpoolid mysqlPoolpsClusterTimer --target $CLUSTER jndi/ps_cluster_timer<br />
<br />
$GLASS_FISH/bin/asadmin delete-jdbc-connection-pool --cascade=true --target $CLUSTER reportPool<br />
$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<br />
$GLASS_FISH/bin/asadmin create-jdbc-resource --connectionpoolid reportPool --target $CLUSTER jndi/reportDS<br />
<br />
$GLASS_FISH/bin/asadmin set $CLUSTER-config.ejb-container.ejb-timer-service.timer-datasource=jndi/ps_cluster_timer<br />
<br />
#$GLASS_FISH/bin/asadmin create-jvm-options --target $CLUSTER -Dcom.sun.enterprise.web.connector.enableJK=8012<br />
#$GLASS_FISH/bin/asadmin create-jvm-options --target $CLUSTER -DjvmRoute=glassfish1<br />
#$GLASS_FISH/bin/asadmin create-jvm-options --target $CLUSTER -DjvmRoute=glassfish2<br />
#$GLASS_FISH/bin/asadmin set $CLUSTER.java-config.classpath-prefix='${com.sun.aas.installRoot}/lib/patch.jar'<br />
#$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'<br />
<br />
<br />
}<br />
<br />
function setupmq () {<br />
<br />
<br />
echo "Prepare for MQ"<br />
echo "============================================================================="<br />
$GLASS_FISH/bin/asadmin delete-jmsdest&nbsp; --desttype queue --target $CLUSTER ActiveMqQueue<br />
$GLASS_FISH/bin/asadmin delete-admin-object --target $CLUSTER jms/ActiveMqQueue<br />
$GLASS_FISH/bin/asadmin delete-connector-resource --target $CLUSTER jms/ActiveMQConnectionFactory<br />
$GLASS_FISH/bin/asadmin delete-connector-connection-pool --target $CLUSTER jms/ActiveMQpool<br />
$GLASS_FISH/bin/asadmin undeploy --target $CLUSTER activemq-rar-5.1.0<br />
echo "finished prepare for MQ"<br />
echo "============================================================================="<br />
<br />
<br />
echo "Start config for MQ"<br />
echo "--------------------------------------------------------------------------------"<br />
$GLASS_FISH/bin/asadmin deploy --target $CLUSTER activemq-rar-5.1.0.rar<br />
echo "finished deploying activemq-rar-5.1.0.rar"<br />
<br />
$GLASS_FISH/bin/asadmin create-admin-object --raname activemq-rar-5.1.0 --restype javax.jms.Queue --property DestinationJndiName=ActiveMqQueue --target $CLUSTER jms/ActiveMqQueue<br />
echo "finished create admin object jms/ActiveMqQueue"<br />
<br />
$GLASS_FISH/bin/asadmin create-jmsdest --desttype queue --target $CLUSTER ActiveMqQueue<br />
echo "finished create jmsdest ActiveMqQueue"<br />
<br />
$GLASS_FISH/bin/asadmin create-connector-connection-pool --raname activemq-rar-5.1.0 --connectiondefinition javax.jms.ConnectionFactory --transactionsupport&nbsp; XATransaction --target $CLUSTER jms/ActiveMQpool<br />
echo "finished create connector connection pool jms/ActiveMQpool"<br />
<br />
$GLASS_FISH/bin/asadmin create-connector-resource --poolname jms/ActiveMQpool --target $CLUSTER jms/ActiveMQConnectionFactory<br />
echo "finished create connector resource jms/ActiveMQConnectionFactory"<br />
<br />
echo "MQ Setup complete"<br />
echo "--------------------------------------------------------------------------------"<br />
<br />
<br />
}<br />
<br />
if [ $# != 9 ]; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo $"Usage: $prog {master|slave cobrand_name glassfish_path DAS_hostname ActiveMQ_path instance_no mysql_username mysql_password mysql_host}"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit 1<br />
fi<br />
<br />
case "$1" in<br />
&nbsp; master)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; common<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; master<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setupmq<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; slave)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; common<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; *)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo $"Usage: $prog {master|slave cobrand_name glassfish_path DAS_hostname ActiveMQ_path instance_no mysql_username mysql_password mysql_host}"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit 1<br />
esac<br />
<br />
<img src ="http://www.blogjava.net/ruoyoux/aggbug/289239.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruoyoux/" target="_blank">Blog of JoJo</a> 2009-07-31 11:53 <a href="http://www.blogjava.net/ruoyoux/articles/289239.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>每日一记 2009/07/29 insert-mysql-statement</title><link>http://www.blogjava.net/ruoyoux/articles/288844.html</link><dc:creator>Blog of JoJo</dc:creator><author>Blog of JoJo</author><pubDate>Wed, 29 Jul 2009 02:13:00 GMT</pubDate><guid>http://www.blogjava.net/ruoyoux/articles/288844.html</guid><wfw:comment>http://www.blogjava.net/ruoyoux/comments/288844.html</wfw:comment><comments>http://www.blogjava.net/ruoyoux/articles/288844.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruoyoux/comments/commentRss/288844.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruoyoux/services/trackbacks/288844.html</trackback:ping><description><![CDATA[[mdrop@authbackup5 jojo]$ cat insert_sql_statement.sql<br />
<br />
#!/usr/bin/perl -w<br />
<br />
#<br />
# Created by: JoJo<br />
# Created Date: 28 July 2009<br />
# Desc: To create the sql statement for Sanriotown Digital<br />
#<br />
<br />
use DateTime;<br />
use DBI;<br />
<br />
<br />
#open log file for writing, append purpose<br />
open(MYLOGFILE, "&gt;&gt; mylog");<br />
<br />
<br />
######### Step 1: Create DB Connection&nbsp; ################################<br />
#definition of variables<br />
$db="UserDB";<br />
$host="localhost";<br />
$socket="/var/lib/auth5-1.us4/mysql1/mysql.sock";<br />
$user="root";<br />
$password="pwd";<br />
<br />
<br />
#connect to MySQL database<br />
my $dbh&nbsp;&nbsp; = DBI-&gt;connect ("DBI:mysql::mysql_socket=$socket;database=$db:host=$host",$user,$password)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or die "Can't connect to database: $DBI::errstr"n";<br />
<br />
<br />
<br />
######### Step 2: Get Active User ################################<br />
<br />
# Get date<br />
my $sdt = DateTime-&gt;now;<br />
# Get active user ( from userdb, usertype != 8)<br />
print MYLOGFILE "Get all active users from cobranddb.sanriotown_com_userdb tables at&nbsp; $sdt."n";<br />
#!`echo 'select username from cobranddb.sanriotown_com_userdb where usertype&nbsp; &amp;8 &lt;&gt; 8 '|mysql -uroot -ppwd --socket=/var/lib/auth5-1.us4/mysql/mysql.sock --skip-column-names &gt;&nbsp; activeuser.txt` || die print "Cannot connect to cobranddb database."n";<br />
# Get date<br />
my $edt = DateTime-&gt;now;<br />
print MYLOGFILE "Finish grep all active users from cobranddb.sanriotown_com_userdb tables at&nbsp; $edt."n";<br />
<br />
<br />
<br />
<br />
######### Step 3: Get Active UserID and Field Value, then Create Insert Statement File#############<br />
<br />
# Open active user file for reading<br />
open (USERFILE, 'activeuser.txt');<br />
# Get date<br />
my $s1dt = DateTime-&gt;now;<br />
# Get active userid and its field value for "country" filedname whose cobrand is "sanriotown.com"<br />
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&nbsp; $s1dt."n";<br />
while (&lt;USERFILE&gt;) {<br />
&nbsp; chomp;<br />
&nbsp; #prepare the query<br />
&nbsp; my $sql = "select&nbsp; 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' ";<br />
&nbsp; my $sth = $dbh-&gt;prepare( $sql);<br />
&nbsp; #execute the query<br />
&nbsp; $sth-&gt;execute( );<br />
<br />
&nbsp; ## Retrieve the results of a row of data and print<br />
&nbsp; my ( $userid,$fieldvalue);<br />
&nbsp; $sth-&gt;bind_columns ( undef,"$userid,"$fieldvalue );<br />
&nbsp; while ( $sth-&gt;fetch( ) )&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #print MYLOGFILE&nbsp; "Userid is $userid and the fieldvalue is $fieldvalue"n";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `echo "insert UserDB.UserProfileTbl values($userid,'orignal_country', '$fieldvalue');" &gt;&gt; insert_sql_statement.sql`;<br />
&nbsp; }<br />
<br />
&nbsp; $sth-&gt;finish( );<br />
}<br />
# Get date<br />
my $e1dt = DateTime-&gt;now;<br />
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&nbsp; $e1dt."n";<br />
<br />
<br />
######### Step 4: Close All File and DB Connection#############<br />
<br />
# Close all opened file <br />
close (USERFILE); <br />
close (MYLOGFILE); <br />
$dbh-&gt;disconnect( );<br />
exit;<br />
<br />
<img src ="http://www.blogjava.net/ruoyoux/aggbug/288844.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruoyoux/" target="_blank">Blog of JoJo</a> 2009-07-29 10:13 <a href="http://www.blogjava.net/ruoyoux/articles/288844.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>每日一记 2009/07/21 squid script for supervise purpose</title><link>http://www.blogjava.net/ruoyoux/articles/287651.html</link><dc:creator>Blog of JoJo</dc:creator><author>Blog of JoJo</author><pubDate>Tue, 21 Jul 2009 06:45:00 GMT</pubDate><guid>http://www.blogjava.net/ruoyoux/articles/287651.html</guid><wfw:comment>http://www.blogjava.net/ruoyoux/comments/287651.html</wfw:comment><comments>http://www.blogjava.net/ruoyoux/articles/287651.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruoyoux/comments/commentRss/287651.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruoyoux/services/trackbacks/287651.html</trackback:ping><description><![CDATA[<ol>
    <li value="5"> Create directory <strong>squid</strong> under <strong>/service/</strong> to let <strong>supervise</strong> start <strong>Squid</strong> automatically
    <ul>
        <li> Cmd: <em>mkdir -p /service/squid</em>
        </li>
    </ul>
    </li>
    <li> Create a <strong>run</strong> file in <strong>/service/squid</strong> with the following content
    <ul>
        <li> <strong>/service/squid/run</strong>
        <pre>#!/bin/sh<br />
        if (test `ps -e | grep -c squid` = 0)<br />
        then<br />
        {<br />
        echo "no squid is running, clean up pid file";<br />
        rm -f /usr/local/site/squid/logs/squid.pid<br />
        }<br />
        fi<br />
        exec /usr/local/site/squid/bin/squid -N<br />
        </pre>
        </li>
    </ul>
    </li>
    <li> Change the permission to <strong>755</strong>, so <strong>supervise</strong> can run it automatically <dl><dt> Cmd</dt><dd> <em>chmod 755 /service/squid/run</em>
    </dd></dl>
    <ul>
        <li> Note: You can verify if a service is started by <strong>supervise</strong> correctly by typing the following command.
        <ul>
            <li> Cmd: <em>svstat /service/*</em>
            </li>
        </ul>
        </li>
        <li> Note: <strong>Squid</strong> cannot start until you fill <strong>/usr/local/site/webroot/errordoc/squid/</strong> with corresponding content later.
        </li>
        <li> Note: If <strong>Squid</strong> 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)
        </li>
    </ul>
    </li>
</ol>
<img src ="http://www.blogjava.net/ruoyoux/aggbug/287651.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruoyoux/" target="_blank">Blog of JoJo</a> 2009-07-21 14:45 <a href="http://www.blogjava.net/ruoyoux/articles/287651.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>每日一记 2009/07/17 mysql init script</title><link>http://www.blogjava.net/ruoyoux/articles/287087.html</link><dc:creator>Blog of JoJo</dc:creator><author>Blog of JoJo</author><pubDate>Fri, 17 Jul 2009 02:02:00 GMT</pubDate><guid>http://www.blogjava.net/ruoyoux/articles/287087.html</guid><wfw:comment>http://www.blogjava.net/ruoyoux/comments/287087.html</wfw:comment><comments>http://www.blogjava.net/ruoyoux/articles/287087.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruoyoux/comments/commentRss/287087.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruoyoux/services/trackbacks/287087.html</trackback:ping><description><![CDATA[[mdrop@jojo1-1 init.d]$ cat mysqld.jojo1-1.us1.master.3306 <br />
#!/bin/bash<br />
#<br />
# mysqld&nbsp;&nbsp; &nbsp;This shell script takes care of starting and stopping<br />
#&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;the MySQL subsystem (mysqld).<br />
#<br />
# chkconfig: - 64 36<br />
# description:&nbsp;&nbsp; &nbsp;MySQL database server.<br />
# processname: mysqld<br />
# config: /etc/my.cnf.jojo1-1.us1.master.3306<br />
# pidfile: /var/run/mysqld-$MYSQLD_SUFFIX/mysqld.pid<br />
<br />
# Source function library.<br />
. /etc/rc.d/init.d/functions<br />
<br />
# Source networking configuration.<br />
. /etc/sysconfig/network<br />
<br />
MYSQLD_SUFFIX="jojo1-1.us1.master.3306"<br />
MYCNF="/etc/my.cnf.$MYSQLD_SUFFIX"<br />
<br />
prog="MySQL"<br />
<br />
# extract value of a MySQL option from config files<br />
# Usage: get_mysql_option SECTION VARNAME DEFAULT<br />
# result is returned in $result<br />
# We use my_print_defaults which prints all options from multiple files,<br />
# with the more specific ones later; hence take the last match.<br />
get_mysql_option(){<br />
&nbsp;&nbsp; &nbsp;#result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`<br />
&nbsp;&nbsp; &nbsp;#if [ -z "$result" ]; then<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; # not found, use default<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; #result="$3"<br />
&nbsp;&nbsp; &nbsp;#fi<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result="$3"<br />
}<br />
<br />
get_mysql_option mysqld datadir "/var/lib/mysql"<br />
datadir="$result"<br />
get_mysql_option mysqld socket "$datadir/mysql.sock"<br />
socketfile="$result"<br />
get_mysql_option mysqld_safe log-error "/var/log/mysqld-$MYSQLD_SUFFIX.log"<br />
errlogfile="$result"<br />
get_mysql_option mysqld_safe pid-file "/var/run/mysqld-$MYSQLD_SUFFIX/mysqld.pid"<br />
mypidfile="$result"<br />
<br />
<br />
start(){<br />
&nbsp;&nbsp; &nbsp;touch "$errlogfile"<br />
&nbsp;&nbsp; &nbsp;chown mysql:mysql "$errlogfile" <br />
&nbsp;&nbsp; &nbsp;chmod 0640 "$errlogfile"<br />
&nbsp;&nbsp; &nbsp;[ -x /sbin/restorecon ] &amp;&amp; /sbin/restorecon "$errlogfile"<br />
&nbsp;&nbsp; &nbsp;if [ ! -d "$datadir/mysql" ] ; then<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; action $"Initializing MySQL database: " /usr/bin/mysql_install_db<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ret=$?<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; chown -R mysql:mysql "$datadir"<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; if [ $ret -ne 0 ] ; then<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return $ret<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp; &nbsp;fi<br />
&nbsp;&nbsp; &nbsp;chown mysql:mysql "$datadir"<br />
&nbsp;&nbsp; &nbsp;chmod 0755 "$datadir"<br />
&nbsp;&nbsp; &nbsp;# Pass all the options determined above, to ensure consistent behavior.<br />
&nbsp;&nbsp; &nbsp;# In many cases mysqld_safe would arrive at the same conclusions anyway<br />
&nbsp;&nbsp; &nbsp;# but we need to be sure.<br />
&nbsp;&nbsp; &nbsp;/usr/bin/mysqld_safe&nbsp; --defaults-file=$MYCNF&nbsp; --datadir="$datadir" --socket="$socketfile" "<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;--log-error="$errlogfile" --pid-file="$mypidfile" "<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&gt;/dev/null 2&gt;&amp;1 &amp;<br />
&nbsp;&nbsp; &nbsp;ret=$?<br />
&nbsp;&nbsp; &nbsp;# Spin for a maximum of N seconds waiting for the server to come up.<br />
&nbsp;&nbsp; &nbsp;# Rather than assuming we know a valid username, accept an "access<br />
&nbsp;&nbsp; &nbsp;# denied" response as meaning the server is functioning.<br />
&nbsp;&nbsp; &nbsp;if [ $ret -eq 0 ]; then<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; STARTTIMEOUT=30<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; while [ $STARTTIMEOUT -gt 0 ]; do<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;RESPONSE=`/usr/bin/mysqladmin -uUNKNOWN_MYSQL_USER ping 2&gt;&amp;1` &amp;&amp; break<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;echo "$RESPONSE" | grep -q "Access denied for user" &amp;&amp; break<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sleep 1<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;let STARTTIMEOUT=${STARTTIMEOUT}-1<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; done<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; if [ $STARTTIMEOUT -eq 0 ]; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "Timeout error occurred trying to start MySQL Daemon."<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action $"Starting $prog: " /bin/false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret=1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action $"Starting $prog: " /bin/true<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp; &nbsp;else<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; action $"Starting $prog: " /bin/false<br />
&nbsp;&nbsp; &nbsp;fi<br />
&nbsp;&nbsp; &nbsp;[ $ret -eq 0 ] &amp;&amp; touch /var/lock/subsys/mysqld.$MYSQLD_SUFFIX<br />
&nbsp;&nbsp; &nbsp;return $ret<br />
}<br />
<br />
stop(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MYSQLPID=`cat "$mypidfile"&nbsp; 2&gt;/dev/null `<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ -n "$MYSQLPID" ]; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /bin/kill "$MYSQLPID" &gt;/dev/null 2&gt;&amp;1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret=$?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ $ret -eq 0 ]; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STOPTIMEOUT=60<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while [ $STOPTIMEOUT -gt 0 ]; do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /bin/kill -0 "$MYSQLPID" &gt;/dev/null 2&gt;&amp;1 || break<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sleep 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let STOPTIMEOUT=${STOPTIMEOUT}-1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; done<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ $STOPTIMEOUT -eq 0 ]; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "Timeout error occurred trying to stop MySQL Daemon."<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret=1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action $"Stopping $prog: " /bin/false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rm -f /var/lock/subsys/mysqld.$MYSQLD_SUFFIX<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rm -f "$socketfile"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action $"Stopping $prog: " /bin/true<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action $"Stopping $prog: " /bin/false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret=1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action $"Stopping $prog: " /bin/false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $ret<br />
}<br />
&nbsp;<br />
restart(){<br />
&nbsp;&nbsp;&nbsp; stop<br />
&nbsp;&nbsp;&nbsp; start<br />
}<br />
<br />
mystatus(){<br />
&nbsp;MYSQLPID=`cat "$mypidfile"&nbsp; 2&gt;/dev/null `<br />
<br />
&nbsp;if [ -n "$MYSQLPID"&nbsp; ]; <br />
&nbsp;then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "mysqld-$MYSQLD_SUFFIX is running"<br />
&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "mysqld-$MYSQLD_SUFFIX is not running"<br />
&nbsp;fi<br />
}<br />
<br />
condrestart(){<br />
&nbsp;&nbsp;&nbsp; [ -e /var/lock/subsys/mysqld.$MYSQLD_SUFFIX ] &amp;&amp; restart || :<br />
}<br />
<br />
# See how we were called.<br />
case "$1" in<br />
&nbsp; start)<br />
&nbsp;&nbsp;&nbsp; start<br />
&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; stop)<br />
&nbsp;&nbsp;&nbsp; stop<br />
&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; status)<br />
&nbsp;&nbsp;&nbsp; #status -p "$mypidfile"&nbsp; mysqld<br />
&nbsp;&nbsp;&nbsp; mystatus<br />
&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; restart)<br />
&nbsp;&nbsp;&nbsp; restart<br />
&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; condrestart)<br />
&nbsp;&nbsp;&nbsp; condrestart<br />
&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; *)<br />
&nbsp;&nbsp;&nbsp; echo $"Usage: $0 {start|stop|status|condrestart|restart}"<br />
&nbsp;&nbsp;&nbsp; exit 1<br />
esac<br />
<br />
exit $?<br />
<br />
<br />
***********************************************************<br />
[mdrop@jojo1-1 init.d]$ cat /etc/my.cnf.jojo1-1.us1.master.3306<br />
[mysqld]<br />
datadir=/var/lib/mysql<br />
socket=/var/lib/mysql/mysql.sock<br />
<br />
port=3306<br />
set-variable = thread_cache_size=950<br />
set-variable = table_cache=4200<br />
set-variable = key_buffer_size=400M<br />
set-variable = record_buffer=100000<br />
set-variable = max_connect_errors=9999999999<br />
set-variable = max_connections=1700<br />
set-variable = tmp_table_size=10M<br />
transaction-isolation = READ-UNCOMMITTED<br />
set-variable = wait_timeout=180<br />
set-variable = max_write_lock_count=120<br />
skip-name-resolve<br />
skip-locking<br />
skip-innodb<br />
set-variable = query_cache_type=1<br />
set-variable = query_cache_size=52428800<br />
log-slow-queries<br />
memlock<br />
<br />
set-variable = max_binlog_size=10M<br />
log-bin=/var/lib/mysql/jojo1-1-us1-log-bin<br />
log-bin-index=/var/lib/mysql/jojo1-1-us1-log-bin.index<br />
server-id=1<br />
&nbsp;&nbsp;&nbsp;&nbsp; <br />
[mysql.server]<br />
user=mysql<br />
basedir=/var/lib<br />
<br />
[safe_mysqld]<br />
err-log=/var/lib/mysql/mysqld.log<br />
pid-file=/var/lib/mysql/mysqld.pid<br />
<br />
<br />
##################################################<br />
<br />
<br />
<br />
[mdrop@jojo1-1 init.d]$ cat mysqld.jojo1-2.us1.slave.3307 <br />
#!/bin/bash<br />
#<br />
# mysqld&nbsp;&nbsp;&nbsp; This shell script takes care of starting and stopping<br />
#&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; the MySQL subsystem (mysqld).<br />
#<br />
# chkconfig: - 64 36<br />
# description:&nbsp;&nbsp;&nbsp; MySQL database server.<br />
# processname: mysqld<br />
# config: /etc/my.cnf.jojo1-2.us1.slave.3307<br />
# pidfile: /var/run/mysqld.jojo1-2.slave/mysqld.pid<br />
<br />
# Source function library.<br />
. /etc/rc.d/init.d/functions<br />
<br />
# Source networking configuration.<br />
. /etc/sysconfig/network<br />
<br />
MYSQLD_SUFFIX="jojo1-2.us1.slave.3307"<br />
MYCNF="/etc/my.cnf.$MYSQLD_SUFFIX"<br />
<br />
prog="MySQL"<br />
<br />
# extract value of a MySQL option from config files<br />
# Usage: get_mysql_option SECTION VARNAME DEFAULT<br />
# result is returned in $result<br />
# We use my_print_defaults which prints all options from multiple files,<br />
# with the more specific ones later; hence take the last match.<br />
get_mysql_option(){<br />
&nbsp;&nbsp;&nbsp; #result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`<br />
&nbsp;&nbsp;&nbsp; #if [ -z "$result" ]; then<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # not found, use default<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; #result="$3"<br />
&nbsp;&nbsp;&nbsp; #fi<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result="$3"<br />
}<br />
<br />
get_mysql_option mysqld datadir "/var/lib/mysql1"<br />
datadir="$result"<br />
get_mysql_option mysqld socket "$datadir/mysql.sock"<br />
socketfile="$result"<br />
get_mysql_option mysqld_safe log-error "/var/log/mysqld-$MYSQLD_SUFFIX.log"<br />
errlogfile="$result"<br />
get_mysql_option mysqld_safe pid-file "/var/run/mysqld-$MYSQLD_SUFFIX/mysqld.pid"<br />
mypidfile="$result"<br />
<br />
<br />
start(){<br />
&nbsp;&nbsp;&nbsp; touch "$errlogfile"<br />
&nbsp;&nbsp;&nbsp; chown mysql:mysql "$errlogfile" <br />
&nbsp;&nbsp;&nbsp; chmod 0640 "$errlogfile"<br />
&nbsp;&nbsp;&nbsp; [ -x /sbin/restorecon ] &amp;&amp; /sbin/restorecon "$errlogfile"<br />
&nbsp;&nbsp;&nbsp; if [ ! -d "$datadir/mysql" ] ; then<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; action $"Initializing MySQL database: " /usr/bin/mysql_install_db<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret=$?<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; chown -R mysql:mysql "$datadir"<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if [ $ret -ne 0 ] ; then<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return $ret<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp;&nbsp; chown mysql:mysql "$datadir"<br />
&nbsp;&nbsp;&nbsp; chmod 0755 "$datadir"<br />
&nbsp;&nbsp;&nbsp; # Pass all the options determined above, to ensure consistent behavior.<br />
&nbsp;&nbsp;&nbsp; # In many cases mysqld_safe would arrive at the same conclusions anyway<br />
&nbsp;&nbsp;&nbsp; # but we need to be sure.<br />
&nbsp;&nbsp;&nbsp; /usr/bin/mysqld_safe&nbsp; --defaults-file=$MYCNF&nbsp; --datadir="$datadir" --socket="$socketfile" "<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; --log-error="$errlogfile" --pid-file="$mypidfile" "<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &gt;/dev/null 2&gt;&amp;1 &amp;<br />
&nbsp;&nbsp;&nbsp; ret=$?<br />
&nbsp;&nbsp;&nbsp; # Spin for a maximum of N seconds waiting for the server to come up.<br />
&nbsp;&nbsp;&nbsp; # Rather than assuming we know a valid username, accept an "access<br />
&nbsp;&nbsp;&nbsp; # denied" response as meaning the server is functioning.<br />
&nbsp;&nbsp;&nbsp; if [ $ret -eq 0 ]; then<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; STARTTIMEOUT=30<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while [ $STARTTIMEOUT -gt 0 ]; do<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RESPONSE=`/usr/bin/mysqladmin -uUNKNOWN_MYSQL_USER ping 2&gt;&amp;1` &amp;&amp; break<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo "$RESPONSE" | grep -q "Access denied for user" &amp;&amp; break<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sleep 1<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; let STARTTIMEOUT=${STARTTIMEOUT}-1<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; done<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if [ $STARTTIMEOUT -eq 0 ]; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "Timeout error occurred trying to start MySQL Daemon."<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action $"Starting $prog: " /bin/false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret=1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action $"Starting $prog: " /bin/true<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; action $"Starting $prog: " /bin/false<br />
&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp;&nbsp; [ $ret -eq 0 ] &amp;&amp; touch /var/lock/subsys/mysqld.$MYSQLD_SUFFIX<br />
&nbsp;&nbsp;&nbsp; return $ret<br />
}<br />
<br />
stop(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MYSQLPID=`cat "$mypidfile"&nbsp; 2&gt;/dev/null `<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ -n "$MYSQLPID" ]; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /bin/kill "$MYSQLPID" &gt;/dev/null 2&gt;&amp;1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret=$?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ $ret -eq 0 ]; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STOPTIMEOUT=60<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while [ $STOPTIMEOUT -gt 0 ]; do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /bin/kill -0 "$MYSQLPID" &gt;/dev/null 2&gt;&amp;1 || break<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sleep 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let STOPTIMEOUT=${STOPTIMEOUT}-1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; done<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ $STOPTIMEOUT -eq 0 ]; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "Timeout error occurred trying to stop MySQL Daemon."<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret=1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action $"Stopping $prog: " /bin/false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rm -f /var/lock/subsys/mysqld.$MYSQLD_SUFFIX<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rm -f "$socketfile"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action $"Stopping $prog: " /bin/true<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action $"Stopping $prog: " /bin/false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret=1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action $"Stopping $prog: " /bin/false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $ret<br />
}<br />
&nbsp;<br />
restart(){<br />
&nbsp;&nbsp;&nbsp; stop<br />
&nbsp;&nbsp;&nbsp; start<br />
}<br />
<br />
mystatus(){<br />
&nbsp;MYSQLPID=`cat "$mypidfile"&nbsp; 2&gt;/dev/null `<br />
<br />
&nbsp;if [ -n "$MYSQLPID"&nbsp; ];<br />
&nbsp;then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "mysqld-$MYSQLD_SUFFIX is running"<br />
&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "mysqld-$MYSQLD_SUFFIX is not running"<br />
&nbsp;fi<br />
}<br />
<br />
<br />
<br />
condrestart(){<br />
&nbsp;&nbsp;&nbsp; [ -e /var/lock/subsys/mysqld.$MYSQLD_SUFFIX ] &amp;&amp; restart || :<br />
}<br />
<br />
# See how we were called.<br />
case "$1" in<br />
&nbsp; start)<br />
&nbsp;&nbsp;&nbsp; start<br />
&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; stop)<br />
&nbsp;&nbsp;&nbsp; stop<br />
&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; status)<br />
&nbsp;&nbsp;&nbsp; #status mysqld<br />
&nbsp;&nbsp;&nbsp; mystatus<br />
&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; restart)<br />
&nbsp;&nbsp;&nbsp; restart<br />
&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; condrestart)<br />
&nbsp;&nbsp;&nbsp; condrestart<br />
&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; *)<br />
&nbsp;&nbsp;&nbsp; echo $"Usage: $0 {start|stop|status|condrestart|restart}"<br />
&nbsp;&nbsp;&nbsp; exit 1<br />
esac<br />
<br />
exit $?<br />
<br />
**********************************************<br />
[mdrop@jojo1-1 init.d]$ cat /etc/my.cnf.jojo1-2.us1.slave.3307<br />
[mysqld]<br />
datadir=/var/lib/mysql1<br />
socket=/var/lib/mysql1/mysql.sock<br />
port=3307<br />
set-variable = thread_cache_size=950<br />
set-variable = table_cache=4200<br />
set-variable = key_buffer_size=400M<br />
set-variable = record_buffer=100000<br />
set-variable = max_connect_errors=9999999999<br />
set-variable = max_connections=950<br />
set-variable = tmp_table_size=10M<br />
transaction-isolation = READ-UNCOMMITTED<br />
set-variable = wait_timeout=500<br />
set-variable = max_write_lock_count=120<br />
skip-name-resolve<br />
skip-locking<br />
skip-innodb<br />
set-variable = query_cache_type=1<br />
set-variable = query_cache_size=52428800<br />
log-slow-queries<br />
memlock<br />
<br />
master-host=192.168.8.73<br />
master-user=repl<br />
master-password=repl12<br />
master-port=3307<br />
master-connect-retry=60<br />
server-id=6239<br />
set-variable = report-host=jojo1-1.us1.outblaze.com:3307<br />
<br />
[mysql.server]<br />
user=mysql<br />
<br />
[safe_mysqld]<br />
err-log=/var/lib/mysql1/mysqld.log<br />
pid-file=/var/lib/mysql1/mysqld.pid<br />
<br />
<br />
<img src ="http://www.blogjava.net/ruoyoux/aggbug/287087.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruoyoux/" target="_blank">Blog of JoJo</a> 2009-07-17 10:02 <a href="http://www.blogjava.net/ruoyoux/articles/287087.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>每日一记 2009/06/16 开机时自动启动APACHE的SCRIPT</title><link>http://www.blogjava.net/ruoyoux/articles/282520.html</link><dc:creator>Blog of JoJo</dc:creator><author>Blog of JoJo</author><pubDate>Tue, 16 Jun 2009 01:31:00 GMT</pubDate><guid>http://www.blogjava.net/ruoyoux/articles/282520.html</guid><wfw:comment>http://www.blogjava.net/ruoyoux/comments/282520.html</wfw:comment><comments>http://www.blogjava.net/ruoyoux/articles/282520.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruoyoux/comments/commentRss/282520.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruoyoux/services/trackbacks/282520.html</trackback:ping><description><![CDATA[#!/bin/bash<br />
#<br />
# httpd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Startup script for the Apache HTTP Server<br />
#<br />
# chkconfig: 345 85 15<br />
# description: Apache is a World Wide Web server.&nbsp; It is used to serve "<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HTML files and CGI.<br />
# processname: httpd<br />
# config: /usr/local/site/apache/conf/httpd.conf<br />
# config: /etc/sysconfig/httpd<br />
# pidfile: /usr/local/site/apache/logs/httpd.pid<br />
<br />
# Source function library.<br />
. /etc/rc.d/init.d/functions<br />
<br />
if [ -f /etc/sysconfig/httpd ]; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; . /etc/sysconfig/httpd<br />
fi<br />
<br />
# Start httpd in the C locale by default.<br />
HTTPD_LANG=${HTTPD_LANG-"C"}<br />
<br />
# This will prevent initlog from swallowing up a pass-phrase prompt if<br />
# mod_ssl needs a pass-phrase from the user.<br />
INITLOG_ARGS=""<br />
<br />
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server<br />
# with the thread-based "worker" MPM; BE WARNED that some modules may not<br />
# work correctly with a thread-based MPM; notably PHP will refuse to start.<br />
<br />
# Path to the apachectl script, server binary, and short-form for messages.<br />
apachectl=/usr/sbin/apachectl<br />
httpd=${HTTPD-/usr/local/site/apache/bin/httpd}<br />
prog=httpd<br />
pidfile=${PIDFILE-/usr/local/site/apache/logs/httpd.pid}<br />
lockfile=${LOCKFILE-/var/lock/subsys/httpd}<br />
RETVAL=0<br />
<br />
# check for 1.3 configuration<br />
check13 () {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CONFFILE=/usr/local/site/apache/conf/httpd.conf<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GONE="${GONE}AccessConfig|ResourceConfig)"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if LANG=C grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo 1&gt;&amp;2 " Apache 1.3 configuration directives found"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo 1&gt;&amp;2 " please read /usr/share/doc/httpd-2.2.3/migration.html"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; failure "Apache 1.3 config directives test"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br />
}<br />
<br />
# The semantics of these two functions differ from the way apachectl does<br />
# things -- attempting to start while running is a failure, and shutdown<br />
# when not running is also a failure.&nbsp; So we just do it the way init scripts<br />
# are expected to behave here.<br />
start() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo -n $"Starting $prog: "<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; check13 || exit 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LANG=$HTTPD_LANG daemon $httpd $OPTIONS<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RETVAL=$?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ $RETVAL = 0 ] &amp;&amp; touch ${lockfile}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $RETVAL<br />
}<br />
<br />
# When stopping httpd a delay of &gt;10 second is required before SIGKILLing the<br />
# httpd parent; this gives enough time for the httpd parent to SIGKILL any<br />
# errant children.<br />
stop() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo -n $"Stopping $prog: "<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; killproc -d 10 $httpd<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RETVAL=$?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [ $RETVAL = 0 ] &amp;&amp; rm -f ${lockfile} ${pidfile}<br />
}<br />
reload() {<br />
&nbsp;&nbsp;&nbsp; echo -n $"Reloading $prog: "<br />
&nbsp;&nbsp;&nbsp; if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t &gt;&amp;/dev/null; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RETVAL=$?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo $"not reloading due to configuration syntax error"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; failure $"not reloading $httpd due to configuration syntax error"<br />
&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; killproc $httpd -HUP<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RETVAL=$?<br />
&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp;&nbsp; echo<br />
}<br />
<br />
# See how we were called.<br />
case "$1" in<br />
&nbsp; start)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; stop)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stop<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; status)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; status $httpd<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RETVAL=$?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; restart)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stop<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; condrestart)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ -f ${pidfile} ] ; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stop<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; reload)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reload<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; graceful|help|configtest|fullstatus)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $apachectl $@<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RETVAL=$?<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br />
&nbsp; *)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit 1<br />
esac<br />
<br />
exit $RETVAL<br />
<br />
<img src ="http://www.blogjava.net/ruoyoux/aggbug/282520.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruoyoux/" target="_blank">Blog of JoJo</a> 2009-06-16 09:31 <a href="http://www.blogjava.net/ruoyoux/articles/282520.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>每日一记 2009/06/11 backup database every day [Script]</title><link>http://www.blogjava.net/ruoyoux/articles/281466.html</link><dc:creator>Blog of JoJo</dc:creator><author>Blog of JoJo</author><pubDate>Thu, 11 Jun 2009 06:17:00 GMT</pubDate><guid>http://www.blogjava.net/ruoyoux/articles/281466.html</guid><wfw:comment>http://www.blogjava.net/ruoyoux/comments/281466.html</wfw:comment><comments>http://www.blogjava.net/ruoyoux/articles/281466.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruoyoux/comments/commentRss/281466.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruoyoux/services/trackbacks/281466.html</trackback:ping><description><![CDATA[#!/usr/bin/perl -w<br />
<br />
#<br />
# Created by: JOJO<br />
# Created Date: 10 June 2009<br />
# Desc: To backup ps corresponding databases for Point System<br />
#<br />
<br />
use strict;<br />
use DateTime;<br />
<br />
<br />
main();<br />
<br />
sub main {<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Get date<br />
&nbsp;&nbsp; &nbsp;my $dt = DateTime-&gt;now; <br />
&nbsp;&nbsp; &nbsp;my $year&nbsp;&nbsp; = $dt-&gt;year;<br />
&nbsp; &nbsp;&nbsp; &nbsp;my $month&nbsp; = sprintf "%02d", $dt-&gt;month;<br />
&nbsp;&nbsp; &nbsp;my $day = sprintf "%02d", $dt-&gt;day;<br />
&nbsp;&nbsp; &nbsp;my $ts = $dt-&gt;epoch();<br />
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp; `mkdir /home/mdrop/PSBackupDB` if (! -d "/home/mdrop/PSBackupDB" );<br />
&nbsp;&nbsp;&nbsp;&nbsp; `mkdir /home/mdrop/PSBackupDBLog` if (! -d "/home/mdrop/PSBackupDBLog" );<br />
&nbsp;&nbsp;&nbsp;&nbsp; `mkdir /home/mdrop/PSBackupDB/$year$month` if (! -d "/home/mdrop/PSBackupDB/$year$month" );<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $dbpath = "/home/mdrop/PSBackupDB";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $logpath = "/home/mdrop/PSBackupDBLog";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $backlog = "$logpath/backup.log";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $user = "root";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $pwd = "password";<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #open log file for writing, append purpose<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; open(MYLOGFILE, "&gt;&gt;$backlog"); <br />
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Export ps db to dump file<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print MYLOGFILE "mysqldump -u$user -p$pwd&nbsp; pointsystem_sd at $dt"n";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`mysqldump -u$user -p$pwd&nbsp; pointsystem_sd &gt; $dbpath/pointsystem_sd.sql-$year$month$day` || die print "Cannot export pointsystem_sd database."n" &gt;&gt; $backlog;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print MYLOGFILE "mysqldump -u$user -p$pwd&nbsp; pointsystem_off at $dt"n";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`mysqldump -u$user -p$pwd&nbsp; pointsystem_off &gt; $dbpath/pointsystem_off.sql-$year$month$day` || die print "Cannot export pointsystem_off database."n" &gt;&gt; $backlog;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print MYLOGFILE "mysqldump -u$user -p$pwd&nbsp; pointsys_log_db at $dt"n";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`mysqldump -u$user -p$pwd&nbsp; pointsys_log_db &gt; $dbpath/pointsys_log_db.sql-$year$month$day` || die print "Cannot export pointsys_log_db database."n" &gt;&gt; $backlog;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print MYLOGFILE "mysqldump -u$user -p$pwd&nbsp; glassfishtimer at $dt"n";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`mysqldump -u$user -p$pwd&nbsp; glassfishtimer &gt; $dbpath/glassfishtimer.sql-$year$month$day` || die print "Cannot export glassfishtimer database."n" &gt;&gt; $backlog;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print MYLOGFILE "mysqldump -u$user -p$pwd&nbsp; obcart at $dt"n";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`mysqldump -u$user -p$pwd&nbsp; obcart &gt; $dbpath/obcart.sql-$year$month$day` || die print "Cannot export obcart database."n" &gt;&gt; $backlog;<br />
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #gzip ps db backup file<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`cd $dbpath; gzip pointsystem_sd.sql-$year$month$day` || die print "Cannot gzip pointsystem_sd.sql-$year$month$day file."n";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`cd $dbpath; gzip pointsystem_off.sql-$year$month$day` || die print "Cannot gzip pointsystem_off.sql-$year$month$day file."n";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`cd $dbpath; gzip pointsys_log_db.sql-$year$month$day` || die print "Cannot gzip pointsys_log_db.sql-$year$month$day file."n" ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`cd $dbpath; gzip glassfishtimer.sql-$year$month$day`&nbsp; || die print "Cannot gzip glassfishtimer.sql-$year$month$day file."n";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`cd $dbpath; gzip obcart.sql-$year$month$day`|| die print "Cannot gzip obcart.sql-$year$month$day database."n";<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #move ps db backup sql file to archive folder<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`mv&nbsp; $dbpath/pointsystem_sd.sql-$year$month$day.gz $dbpath/$year$month` || die print "Cannot move pointsystem_sd.sql-$year$month$day.gz file."n";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`mv&nbsp; $dbpath/pointsystem_off.sql-$year$month$day.gz $dbpath/$year$month` || die print "Cannot move pointsystem_off.sql-$year$month$day.gz file."n";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`mv&nbsp; $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";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`mv&nbsp; $dbpath/glassfishtimer.sql-$year$month$day.gz $dbpath/$year$month`&nbsp; || die print "Cannot move glassfishtimer.sql-$year$month$day.gz file."n";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !`mv&nbsp; $dbpath/obcart.sql-$year$month$day.gz $dbpath/$year$month`|| die print "Cannot move glassfishtimer.sql-$year$month$day.gz file."n";<br />
<br />
}<br />
<br />
<img src ="http://www.blogjava.net/ruoyoux/aggbug/281466.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruoyoux/" target="_blank">Blog of JoJo</a> 2009-06-11 14:17 <a href="http://www.blogjava.net/ruoyoux/articles/281466.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>每日一记 2009/06/10 Running Glassfish as a service on CentOS</title><link>http://www.blogjava.net/ruoyoux/articles/281155.html</link><dc:creator>Blog of JoJo</dc:creator><author>Blog of JoJo</author><pubDate>Wed, 10 Jun 2009 06:39:00 GMT</pubDate><guid>http://www.blogjava.net/ruoyoux/articles/281155.html</guid><wfw:comment>http://www.blogjava.net/ruoyoux/comments/281155.html</wfw:comment><comments>http://www.blogjava.net/ruoyoux/articles/281155.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruoyoux/comments/commentRss/281155.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruoyoux/services/trackbacks/281155.html</trackback:ping><description><![CDATA[<p>Here is how you run glassfish as a service on CentOS:</p>
<ol>
    <li> Create a user <em>glassfish (</em>you can call it anything you want) under which Glassfish will run.
    <div>
    <div>
    <pre style="font-family: monospace;"><span style="color: #666666; font-style: italic;">#useradd glassfish</span></pre>
    </div>
    </div>
    </li>
    <li> <a href="https://glassfish.dev.java.net/downloads/v2.1-b60e.html">Install glassfish</a> in /home/glassfish.</li>
    <li>Create the startup script <em>/etc/init.d/glassifsh</em> for glassfish.
    <div>
    <table>
        <tbody>
            <tr>
                <td>
                <pre style="font-family: monospace;"><span style="color: #666666; font-style: italic;">                #!/bin/bash</span><br />
                <span style="color: #666666; font-style: italic;">#</span><br />
                <span style="color: #666666; font-style: italic;"># glassfish:          Startup script for Glassfish Application Server.</span><br />
                <span style="color: #666666; font-style: italic;">#</span><br />
                <span style="color: #666666; font-style: italic;"># chkconfig: 3 80 05</span><br />
                <span style="color: #666666; font-style: italic;"># description:      Startup script for domain1 of Glassfish Application Server.</span><br />
                <span style="color: #007800;"><br />
                GLASSFISH_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>glassfish<span style="color: #000000; font-weight: bold;">/</span>glassfish;<br />
                <span style="color: #7a0874; font-weight: bold;">export</span> GLASSFISH_HOME<br />
                <span style="color: #007800;">GLASSFISH_OWNER</span>=glassfish;<br />
                <span style="color: #7a0874; font-weight: bold;">export</span> GLASSFISH_OWNER<br />
                <br />
                start<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #7a0874; font-weight: bold;">)</span> <span style="color: #7a0874; font-weight: bold;">{</span><br />
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">"Starting Glassfish: "</span><br />
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Starting Glassfish at <span style="color: #780078;">`date`</span>"</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$GLASSFISH_HOME</span><span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>domain1<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>startup.log<br />
                <span style="color: #c20cb9; font-weight: bold;">su</span> <span style="color: #007800;">$GLASSFISH_OWNER</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">"<span style="color: #007800;">$GLASSFISH_HOME</span>/bin/asadmin start-domain domain1"</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$GLASSFISH_HOME</span><span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>domain1<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>startup.log<br />
                <br />
                <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">2</span><br />
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"done"</span><br />
                <span style="color: #7a0874; font-weight: bold;">}</span><br />
                <br />
                stop<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #7a0874; font-weight: bold;">)</span> <span style="color: #7a0874; font-weight: bold;">{</span><br />
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">"Stopping Glassfish: "</span><br />
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Stopping Glassfish at <span style="color: #780078;">`date`</span>"</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$GLASSFISH_HOME</span><span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>domain1<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>startup.log<br />
                <span style="color: #c20cb9; font-weight: bold;">su</span> <span style="color: #007800;">$GLASSFISH_OWNER</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">"<span style="color: #007800;">$GLASSFISH_HOME</span>/bin/asadmin stop-domain domain1"</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$GLASSFISH_HOME</span><span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>domain1<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>startup.log<br />
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"done"</span><br />
                <span style="color: #7a0874; font-weight: bold;">}</span><br />
                <br />
                <span style="color: #666666; font-style: italic;"># See how we were called.</span><br />
                <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">"$1"</span> <span style="color: #000000; font-weight: bold;">in</span><br />
                start<span style="color: #7a0874; font-weight: bold;">)</span><br />
                <br />
                start<br />
                <span style="color: #000000; font-weight: bold;">  ;;</span><br />
                <br />
                stop<span style="color: #7a0874; font-weight: bold;">)</span><br />
                stop<br />
                <span style="color: #000000; font-weight: bold;">;;</span><br />
                <br />
                restart<span style="color: #7a0874; font-weight: bold;">)</span><br />
                stop<br />
                start<br />
                <span style="color: #000000; font-weight: bold;"> ;;</span><br />
                <br />
                <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">)</span><br />
                <span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #ff0000;">"Usage: glassfish {start|stop|restart}"</span><br />
                <span style="color: #7a0874; font-weight: bold;">exit</span><br />
                <span style="color: #000000; font-weight: bold;">esac</span></pre>
                </td>
            </tr>
        </tbody>
    </table>
    </div>
    </li>
    <li>Install the service
    <div>
    <div>
    <pre style="font-family: monospace;"><span style="color: #666666; font-style: italic;">#chmod +x /etc/init.d/glassfish</span><br />
    <span style="color: #666666; font-style: italic;">#chkconfig -add glassfish</span><br />
    <span style="color: #666666; font-style: italic;">#chkconfig --level 3 glassfish on</span></pre>
    </div>
    </div>
    </li>
    <li>Start glassfish.
    <div>
    <div>
    <pre style="font-family: monospace;"><span style="color: #666666; font-style: italic;">#/etc/init.d/glassfish start</span></pre>
    </div>
    </div>
    </li>
</ol>
<img src ="http://www.blogjava.net/ruoyoux/aggbug/281155.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruoyoux/" target="_blank">Blog of JoJo</a> 2009-06-10 14:39 <a href="http://www.blogjava.net/ruoyoux/articles/281155.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>每日一记 2009/06/10  Autostarting Glassfish on CentOS</title><link>http://www.blogjava.net/ruoyoux/articles/281154.html</link><dc:creator>Blog of JoJo</dc:creator><author>Blog of JoJo</author><pubDate>Wed, 10 Jun 2009 06:38:00 GMT</pubDate><guid>http://www.blogjava.net/ruoyoux/articles/281154.html</guid><wfw:comment>http://www.blogjava.net/ruoyoux/comments/281154.html</wfw:comment><comments>http://www.blogjava.net/ruoyoux/articles/281154.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruoyoux/comments/commentRss/281154.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruoyoux/services/trackbacks/281154.html</trackback:ping><description><![CDATA[<div>
<p>I&#8217;ve been working with <a href="https://glassfish.dev.java.net/" target="_blank">Glassfish</a>
recently, from the system administration point of view.&nbsp; 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.</p>
<p>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.&nbsp; The
fiddling in start() gets around the fact that Glassfish doesn&#8217;t seem to
write a PID file out where we need one.</p>
<p>So, just in case anyone else needs to do this:</p>
<div>
<div>
<pre><span style="color: #808080; font-style: italic;">#!/bin/bash</span><br />
<span style="color: #808080; font-style: italic;"># chkconfig: 2345 85 15</span><br />
<span style="color: #808080; font-style: italic;"># description: GlassFish is a Java Application Server.</span><br />
<span style="color: #808080; font-style: italic;"># processname: glassfish</span><br />
<span style="color: #808080; font-style: italic;"># pidfile: /var/run/glassfish.pid</span><br />
<br />
<span style="color: #808080; font-style: italic;"># source function library</span><br />
. <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>functions<br />
<br />
<span style="color: #007800;">RETVAL=</span><span style="color: #000000;">0</span><br />
<br />
<span style="color: #007800;">GLASSFISH_BIN=</span><span style="color: #ff0000;">"/var/lib/glassfish/bin"</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Basename works with symbolic links.</span><br />
<span style="color: #007800;">NAME=</span><span style="color: #ff0000;">"$(basename $0)"</span><br />
<span style="color: #7a0874; font-weight: bold;">unset</span> ISBOOT<br />
<br />
<span style="color: #808080; font-style: italic;"># Trim off the Sxx/Kxx prefix</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #ff0000;">"${NAME:0:1}"</span> = <span style="color: #ff0000;">"S"</span> -o <span style="color: #ff0000;">"${NAME:0:1}"</span> = <span style="color: #ff0000;">"K"</span> <span style="color: #7a0874; font-weight: bold;">]</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
<span style="color: #007800;">NAME=</span><span style="color: #ff0000;">"${NAME:3}"</span><br />
<span style="color: #007800;">ISBOOT=</span><span style="color: #ff0000;">"1"</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Trim off the glassfish- prefix</span><br />
<span style="color: #007800;">NAME=</span>$<span style="color: #7a0874; font-weight: bold;">{</span>NAME:<span style="color: #000000;">10</span><span style="color: #7a0874; font-weight: bold;">}</span><br />
<br />
<span style="color: #808080; font-style: italic;"># /etc/init.d/glassfish should never be called directly.</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> -z <span style="color: #007800;">$NAME</span> <span style="color: #7a0874; font-weight: bold;">]</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> -n $<span style="color: #ff0000;">"Cannot start Glassfish without specifying a domain."</span><br />
failure<br />
<span style="color: #7a0874; font-weight: bold;">echo</span><br />
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
start<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #7a0874; font-weight: bold;">)</span> <span style="color: #7a0874; font-weight: bold;">{</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> -n $<span style="color: #ff0000;">"Starting Glassfish V2 domain $NAME: "</span><br />
daemon --user glassfish --pidfile <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>glassfish-<span style="color: #007800;">$NAME</span>.pid <span style="color: #ff0000;">"$GLASSFISH_BIN/asadmin start-domain $NAME &amp;gt;/dev/null 2&amp;gt;&amp;amp;1"</span><br />
<span style="color: #007800;">RETVAL=</span><span style="color: #007800;">$?</span><br />
<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #007800;">$RETVAL</span> -eq <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">]</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
<span style="color: #007800;">PID=</span>`<span style="color: #c20cb9; font-weight: bold;">ps</span> U glassfish <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$NAME</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $1}'</span>`<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$PID</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>glassfish-<span style="color: #007800;">$NAME</span>.pid<br />
<span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lock<span style="color: #000000; font-weight: bold;">/</span>subsys<span style="color: #000000; font-weight: bold;">/</span>glassfish-<span style="color: #007800;">$NAME</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span><br />
<span style="color: #7a0874; font-weight: bold;">}</span><br />
<br />
<br />
stop<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #7a0874; font-weight: bold;">)</span> <span style="color: #7a0874; font-weight: bold;">{</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> -n $<span style="color: #ff0000;">"Shutting down Glassfish V2 domain $NAME: "</span><br />
<br />
<span style="color: #007800;">$GLASSFISH_BIN</span><span style="color: #000000; font-weight: bold;">/</span>asadmin stop-domain <span style="color: #007800;">$NAME</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000;">1</span><br />
<br />
<span style="color: #007800;">RETVAL=</span><span style="color: #007800;">$?</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #007800;">$RETVAL</span> -eq <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">]</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #c20cb9; font-weight: bold;">rm</span> -f <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lock<span style="color: #000000; font-weight: bold;">/</span>subsys<span style="color: #000000; font-weight: bold;">/</span>glassfish-<span style="color: #007800;">$NAME</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #c20cb9; font-weight: bold;">rm</span> -f <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>glassfish-<span style="color: #007800;">$NAME</span>  <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; success <span style="color: #000000; font-weight: bold;">||</span> failure<br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">}</span><br />
<br />
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">"$1"</span> <span style="color: #000000; font-weight: bold;">in</span><br />
<br />
start<span style="color: #7a0874; font-weight: bold;">)</span><br />
<br />
start<br />
<br />
<span style="color: #000000; font-weight: bold;">;;</span><br />
<br />
stop<span style="color: #7a0874; font-weight: bold;">)</span><br />
<br />
stop<br />
<span style="color: #000000; font-weight: bold;">;;</span><br />
<br />
restart<span style="color: #000000; font-weight: bold;">|</span>reload<span style="color: #7a0874; font-weight: bold;">)</span><br />
<br />
stop<br />
<br />
start<br />
<br />
<span style="color: #000000; font-weight: bold;">;;</span><br />
<br />
condrestart<span style="color: #7a0874; font-weight: bold;">)</span><br />
<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> -f <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lock<span style="color: #000000; font-weight: bold;">/</span>subsys<span style="color: #000000; font-weight: bold;">/</span>glassfish-<span style="color: #007800;">$NAME</span> <span style="color: #7a0874; font-weight: bold;">]</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
<br />
stop<br />
<br />
start<br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">;;</span><br />
<br />
status<span style="color: #7a0874; font-weight: bold;">)</span><br />
status glassfish-<span style="color: #007800;">$NAME</span><br />
<br />
<span style="color: #007800;">RETVAL=</span><span style="color: #007800;">$?</span><br />
<span style="color: #000000; font-weight: bold;">;;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">)</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #ff0000;">"Usage: $0 {start|stop|restart|condrestart|status}"</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
<br />
<span style="color: #000000; font-weight: bold;">esac</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$RETVAL</span></pre>
</div>
</div>
<p>The alternative is to define a /etc/sysconfig/glassfish file, and
insert a variable with the list of domains to boot, in sequence.&nbsp; This
is a little harder to manage automatically in <a href="http://reductivelabs.com/projects/puppet/" target="_blank">Puppet</a>,
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).</p>
</div>
<img src ="http://www.blogjava.net/ruoyoux/aggbug/281154.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruoyoux/" target="_blank">Blog of JoJo</a> 2009-06-10 14:38 <a href="http://www.blogjava.net/ruoyoux/articles/281154.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>