2014-05-28 Ramon Novoa <rnovoa@artica.es>

* bin/pandora_server,
	  lib/PandoraFMS/Config.pm: Removed getopts. Fixes a problem found by Junichi.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10027 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2014-05-28 09:37:01 +00:00
parent e20cd34e6f
commit 490d1b603e
3 changed files with 40 additions and 44 deletions

View File

@ -1,3 +1,8 @@
2014-05-28 Ramon Novoa <rnovoa@artica.es>
* bin/pandora_server,
lib/PandoraFMS/Config.pm: Removed getopts. Fixes a problem found by Junichi.
2014-05-27 Ramon Novoa <rnovoa@artica.es> 2014-05-27 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/Tools.pm: If no logfile is defined print the message to * lib/PandoraFMS/Tools.pm: If no logfile is defined print the message to

View File

@ -19,7 +19,6 @@
use strict; use strict;
use warnings; use warnings;
use Getopt::Std;
use POSIX qw(strftime); use POSIX qw(strftime);
use threads; use threads;
@ -148,7 +147,7 @@ sub pandora_crash () {
# worried about that. If perl has a more "clean" way to avoid this messages # worried about that. If perl has a more "clean" way to avoid this messages
# will be nice to replace this code, but at this time it's the only way I know # will be nice to replace this code, but at this time it's the only way I know
callback_stop() if (defined($Config{'__win32_service__'})); callback_stop() if ($^O eq 'MSWin32' && defined($Config{'win32_service'}));
foreach my $error_line (@_) { foreach my $error_line (@_) {
# Trap the XML error and exit without nasty messages # Trap the XML error and exit without nasty messages
@ -448,36 +447,24 @@ sub win32_service_run() {
################################################################################ ################################################################################
## Parse command line options. ## Parse command line options.
################################################################################ ################################################################################
sub parse_options { sub parse_service_options ($) {
my %opts; my $config = shift;
my $tmp;
my @t_addresses_tmp;
# Get options # Sanity checks.
if (getopts('S:', \%opts) == 0 || defined ($opts{'h'})) { return unless defined($config->{'win32_service'});
print_help (); die ("[ERROR] Windows services are only available on Win32.\n\n") if ($^O ne 'MSWin32');
exit 1;
}
# Win32 service management # Win32 service management.
if (defined ($opts{'S'})) {
my $service_action = $opts{'S'};
if ($^O ne 'MSWin32') {
error ("Windows services are only available on Win32.");
} else {
eval "use Win32::Daemon"; eval "use Win32::Daemon";
die($@) if ($@); die($@) if ($@);
if ($service_action eq 'install') { if ($config->{'win32_service'} eq 'install') {
win32_install_service(); win32_install_service();
} elsif ($service_action eq 'uninstall') { } elsif ($config->{'win32_service'} eq 'uninstall') {
win32_uninstall_service(); win32_uninstall_service();
} elsif ($service_action eq 'run') { } elsif ($config->{'win32_service'} eq 'run') {
$Config{'__win32_service__'} == 1;
} else { } else {
error("Unknown action: $service_action"); die("[ERROR] Unknown action: " . $config->{'win32_service'});
}
}
} }
} }
@ -488,19 +475,6 @@ sub parse_options {
################################################################ ################################################################
sub main() { sub main() {
$SIG{'TERM'} = 'pandora_shutdown';
$SIG{'INT'} = 'pandora_shutdown';
# Error handler needs to be reviewed, Enterprise not found errors are too nasty :(
$SIG{__DIE__} = 'pandora_crash';
# Prevent alarm from bombing the main thread when called within a thread
$SIG{'ALRM'} = 'IGNORE';
# Initialize
pandora_init(\%Config, 'Pandora FMS Server');
pandora_load_config (\%Config);
# Daemonize and put in background # Daemonize and put in background
if ($Config{'daemon'} == 1) { if ($Config{'daemon'} == 1) {
print_message (\%Config, " [*] Backgrounding Pandora FMS Server process.\n", 1); print_message (\%Config, " [*] Backgrounding Pandora FMS Server process.\n", 1);
@ -623,11 +597,24 @@ sub main() {
pandora_shutdown(); pandora_shutdown();
} }
$SIG{'TERM'} = 'pandora_shutdown';
$SIG{'INT'} = 'pandora_shutdown';
# Error handler needs to be reviewed, Enterprise not found errors are too nasty :(
$SIG{__DIE__} = 'pandora_crash';
# Prevent alarm from bombing the main thread when called within a thread
$SIG{'ALRM'} = 'IGNORE';
# Initialize
pandora_init(\%Config, 'Pandora FMS Server');
pandora_load_config (\%Config);
# Parse command line options. # Parse command line options.
parse_options(); parse_service_options(\%Config);
# Run as a regular process. # Run as a regular process.
if (!defined($Config{'__win32_service__'})) { if (!defined($Config{'win32_service'})) {
main(); main();
} }
# Run as a Windows service. # Run as a Windows service.

View File

@ -63,6 +63,7 @@ sub help_screen {
print " -D : Daemon mode (runs in background)\n"; print " -D : Daemon mode (runs in background)\n";
print " -P <file> : Store PID to file.\n"; print " -P <file> : Store PID to file.\n";
print " -q : Quiet startup \n"; print " -q : Quiet startup \n";
print " -S <install|uninstall|run>: Manage the win32 service.\n";
print " -h : This screen. Shows a little help screen \n"; print " -h : This screen. Shows a little help screen \n";
print " \n"; print " \n";
exit; exit;
@ -115,6 +116,9 @@ sub pandora_init {
elsif ($parametro =~ m/-D\z/) { elsif ($parametro =~ m/-D\z/) {
$pa_config->{"daemon"}=1; $pa_config->{"daemon"}=1;
} }
elsif ($parametro =~ m/^-S\z/i) {
$pa_config->{'win32_service'}= clean_blank($ARGV[$ax+1]);
}
else { else {
($pa_config->{"pandora_path"} = $parametro); ($pa_config->{"pandora_path"} = $parametro);
} }