From d4693a320d95b5bc16b18e4d310976552c86c21e Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Thu, 10 Jan 2013 12:18:28 +0100 Subject: [PATCH] last update for 3.0.0beta1 --- docs/monitorix.spec | 7 ++--- monitorix | 63 +++++++++++++++------------------------------ monitorix.cgi | 3 ++- monitorix.conf | 8 +++--- 4 files changed, 31 insertions(+), 50 deletions(-) diff --git a/docs/monitorix.spec b/docs/monitorix.spec index d6f49e8..cade42f 100644 --- a/docs/monitorix.spec +++ b/docs/monitorix.spec @@ -47,7 +47,9 @@ install -m 0644 docs/monitorix.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/mo mkdir -p %{buildroot}%{_sysconfdir} install -m 0644 monitorix.conf %{buildroot}%{_sysconfdir}/monitorix.conf mkdir -p %{buildroot}%{_bindir} -install -m 0755 monitorix %{buildroot}%{_bindir} +install -m 0755 monitorix %{buildroot}%{_bindir}/monitorix +mkdir -p %{buildroot}%{_libdir}/monitorix +install -m 0644 lib/*.pm %{buildroot}%{_libdir}/monitorix mkdir -p %{buildroot}%{_datadir}/monitorix install -m 0644 logo_top.png %{buildroot}%{_datadir}/monitorix install -m 0644 logo_bot.png %{buildroot}%{_datadir}/monitorix @@ -57,7 +59,6 @@ mkdir -p %{buildroot}%{_datadir}/monitorix/cgi-bin install -m 0755 monitorix.cgi %{buildroot}%{_datadir}/monitorix/cgi-bin mkdir -p %{buildroot}%{_localstatedir}/lib/monitorix/reports install -m 0644 reports/*.html %{buildroot}%{_localstatedir}/lib/monitorix/reports -install -m 0755 reports/send_reports %{buildroot}%{_localstatedir}/lib/monitorix/reports mkdir -p %{buildroot}%{_localstatedir}/lib/monitorix/usage mkdir -p %{buildroot}%{_mandir}/man5 mkdir -p %{buildroot}%{_mandir}/man8 @@ -78,6 +79,7 @@ rm -rf %{buildroot} %config(noreplace) %{_sysconfdir}/sysconfig/monitorix %config(noreplace) %{_sysconfdir}/monitorix.conf %{_bindir}/monitorix +%{_libdir}/monitorix/*.pm %{_datadir}/monitorix/logo_top.png %{_datadir}/monitorix/logo_bot.png %{_datadir}/monitorix/monitorixico.png @@ -85,7 +87,6 @@ rm -rf %{buildroot} %attr(777,apache,apache) %{_datadir}/monitorix/imgs %attr(755,root,root) %{_localstatedir}/lib/monitorix/usage %config(noreplace) %{_localstatedir}/lib/monitorix/reports/*.html -%{_localstatedir}/lib/monitorix/reports/send_reports %doc %{_mandir}/man5/monitorix.conf.5.gz %doc %{_mandir}/man8/monitorix.8.gz %doc Changes COPYING README README.nginx README.FreeBSD README.OpenBSD README.NetBSD docs/monitorix-alert.sh docs/monitorix-lighttpd.conf diff --git a/monitorix b/monitorix index 91862cd..d641052 100755 --- a/monitorix +++ b/monitorix @@ -24,10 +24,11 @@ require 5.006; use strict; use warnings; use FindBin qw($Bin); -use lib $Bin . '/lib'; +use lib "$Bin/lib"; +use lib "/usr/lib/monitorix"; use Monitorix; -use POSIX qw(WNOHANG LC_TIME setlocale uname pause); +use POSIX qw(WNOHANG LC_TIME setlocale uname pause setsid); use Config::General; use Getopt::Std; use Cwd 'abs_path'; @@ -75,12 +76,8 @@ sub HUP_handler { # upon receiving a SIGHUP signal the logfile is re-opened close(STDOUT); close(STDERR); - unless(open(STDOUT, ">> $config{log_file}")) { - logger("Can't write to LOG: $!"); - } - unless(open(STDERR, ">> $config{log_file}")) { # >>&STDOUT XXX - logger("Can't write to LOG: $!"); - } + open(STDOUT, ">> $config{log_file}") || logger("Can't write to LOG: $!"); + open(STDERR, ">> $config{log_file}") || logger("Can't write to LOG: $!"); logger("$myself: reopening log file."); } @@ -135,29 +132,13 @@ sub ALRM_handler { } sub daemonize { - if(fork) { - exit(0); # parent exits - } - - setsid(); - foreach(0 .. (sysconf(&POSIX::_SC_OPEN_MAX) || 1024)) { - close($_); - } - unless(chdir("/")) { - die("Can't chdir to /: $!"); - } - unless(umask(022)) { - die("Unable to umask 022: $!"); - } -# unless(open(STDIN, "< /dev/null")) { -# die("Can't read /dev/null: $!"); -# } - unless(open(STDOUT, ">> $config{log_file}")) { - die("Can't write to LOG: $!"); - } - unless(open(STDERR, ">> $config{log_file}")) { # >>&STDOUT XXX - die("Can't write to LOG: $!"); - } + chdir("/") || die "Can't chdir to /: $!"; + open(STDIN, "< /dev/null") || die "Can't read /dev/null: $!"; + open(STDOUT, ">> $config{log_file}") || die "Can't write to LOG: $!"; + umask(022) || die "Unable to umask 022: $!"; + exit if fork(); # parent exits + (setsid() != -1) || die "Can't start a new session: $!"; + open(STDERR, ">> $config{log_file}") || die "Can't write to LOG: $!"; } sub usage { @@ -194,7 +175,7 @@ sub create_index { } if(!open(OUT, "> $config{base_dir}/index.html")) { - die "unable to create '${config{base_dir}}index.html'. $!"; + die "unable to create '${config{base_dir}}index.html': $!"; } print(OUT < @@ -387,7 +368,7 @@ if(!$options{c}) { } $options{c} = abs_path($options{c}) unless $^V lt 5.6.2; if(!stat($options{c})) { - die("can't open file '$options{c}'.\n"); + die "can't open file '$options{c}': $!"; } # load configuration file @@ -404,7 +385,7 @@ my $release; my ($major, $minor) = split('\.', $release); $config{kernel} = $major . "." . $minor; if(!grep {$_ eq $config{os}} @suppsys) { - die("FATAL: your operating system ($config{os}) is not supported.\n"); + die "FATAL: your operating system ($config{os}) is not supported."; } if(grep {$_ eq $config{os}} ("FreeBSD", "OpenBSD", "NetBSD")) { @@ -418,13 +399,13 @@ $0 = sprintf("%s %s%s%s%s", $options{d} ? " -d $options{d}" : "", $options{v} ? " -v" : ""); -#daemonize(); +daemonize(); logger("Starting Monitorix version " . VERSION . " (pid $$)."); if($options{p}) { $options{p} = abs_path($options{p}); open(OUT, "> $options{p}") - || die("could not open '$options{p}' for writing"); + || die "could not open '$options{p}' for writing: $!"; print(OUT "$$"); close(OUT); } @@ -432,9 +413,7 @@ if($options{p}) { # change to a safety directory unless(chdir("/tmp")) { logger("can't chdir to /tmp: $!"); - unless(chdir("/lost+found")) { - die("Can't chdir to /lost+found: $!"); - } + chdir("/lost+found") || die "Can't chdir to /lost+found: $!"; } if($options{d}) { @@ -442,7 +421,7 @@ if($options{d}) { @{$config{debug}} = split(',', $options{d}); foreach my $t (@{$config{debug}}) { if(!grep {trim($_) eq $t} (split(',', $config{graph_name} . ", traffacct"))) { - die("Invalid debug key '$t'"); + die "Invalid debug key '$t'"; } } } @@ -494,8 +473,8 @@ foreach (split(',', $config{graph_name} . ", traffacct")) { } # XXX -use Data::Dumper; -print Dumper($config{func_update}); +#use Data::Dumper; +#print Dumper($config{func_update}); # XXX if(!scalar($config{func_update})) { diff --git a/monitorix.cgi b/monitorix.cgi index 7875d7c..093c696 100755 --- a/monitorix.cgi +++ b/monitorix.cgi @@ -22,7 +22,8 @@ use strict; use warnings; use FindBin qw($Bin); -use lib $Bin . '/lib'; +use lib "$Bin/lib"; +use lib "/usr/lib/monitorix"; use Monitorix; use CGI qw(:standard); diff --git a/monitorix.conf b/monitorix.conf index e563b29..b0a76f9 100644 --- a/monitorix.conf +++ b/monitorix.conf @@ -12,10 +12,10 @@ enable_zoom = y netstats_in_bps = n disable_javascript_void = n -base_dir = /usr/share/monitorix3/ -base_lib = /var/lib/monitorix3/ -base_url = /monitorix3 -base_cgi = /monitorix-cgi3 +base_dir = /usr/share/monitorix/ +base_lib = /var/lib/monitorix/ +base_url = /monitorix +base_cgi = /monitorix-cgi # Log files pathnames