Skip to content

Instantly share code, notes, and snippets.

@olesku
Last active November 11, 2016 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olesku/46c2b9da595506d7ff9c505906ca9f21 to your computer and use it in GitHub Desktop.
Save olesku/46c2b9da595506d7ff9c505906ca9f21 to your computer and use it in GitHub Desktop.
#!/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