Last active
November 11, 2016 11:05
-
-
Save olesku/46c2b9da595506d7ff9c505906ca9f21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
my @tomcatInitScriptPaths = ( "/etc/init.d/tomcat", "/etc/init.d/tomcat6" ); | |
# Do not change from here. | |
my $tomcatInitScript; | |
foreach (@tomcatInitScriptPaths) { $tomcatInitScript = $_ if ( -e $_ ); } | |
die("Error: Could not find Tomcat init script.\n") unless($tomcatInitScript); | |
sub killTomcat { | |
my $tomcat_pids; | |
for($i = 0; $i < 3; $i++) { | |
$tomcat_pids = `pidof jsvc.exec`; | |
$tomcat_pids =~ s/\n//; | |
if ($tomcat_pids) { | |
system($tomcatInitScript . " stop"); | |
} else { | |
undef($tomcat_pids); | |
last; | |
} | |
} | |
if ($tomcat_pids) { | |
system("kill -9 " . $tomcat_pids); | |
} | |
} | |
sub startTomcat { | |
system($tomcatInitScript . " start"); | |
} | |
sub tomcatStatus { | |
$tomcat_pids = `pidof jsvc.exec`; | |
if ($tomcat_pids) { | |
print("Tomcat is running with PIDS: " . $tomcat_pids); | |
} else { | |
print("Tomcat is not running.\n"); | |
} | |
} | |
if ($ARGV[0] eq "start") { | |
startTomcat(); | |
} elsif ($ARGV[0] eq "stop") { | |
killTomcat(); | |
} elsif ($ARGV[0] eq "status") { | |
tomcatStatus(); | |
} else { | |
die("Usage: " . $0 . " start | stop | restart\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment