[pve-devel] r5639 - in pve-manager/pve2: bin bin/init.d debian
svn-commits at proxmox.com
svn-commits at proxmox.com
Thu Mar 3 08:14:23 CET 2011
Author: dietmar
Date: 2011-03-03 08:14:23 +0100 (Thu, 03 Mar 2011)
New Revision: 5639
Added:
pve-manager/pve2/bin/init.d/pvestatd
pve-manager/pve2/bin/pvestatd
Modified:
pve-manager/pve2/bin/Makefile.am
pve-manager/pve2/bin/Makefile.in
pve-manager/pve2/bin/init.d/Makefile.am
pve-manager/pve2/bin/init.d/Makefile.in
pve-manager/pve2/bin/pvedaemon
pve-manager/pve2/debian/conffiles
pve-manager/pve2/debian/postinst
pve-manager/pve2/debian/postrm
Log:
implement status daemon - first try
Modified: pve-manager/pve2/bin/Makefile.am
===================================================================
--- pve-manager/pve2/bin/Makefile.am 2011-03-03 06:57:36 UTC (rev 5638)
+++ pve-manager/pve2/bin/Makefile.am 2011-03-03 07:14:23 UTC (rev 5639)
@@ -3,6 +3,7 @@
SUBDIRS = init.d cron test
bin_SCRIPTS = \
+ pvestatd \
pvesh \
pveam \
pvebanner \
@@ -14,6 +15,7 @@
pveperf
man_MANS = \
+ pvestatd.1 \
pvedaemon.1 \
pveversion.1 \
pveperf.1
Modified: pve-manager/pve2/bin/Makefile.in
===================================================================
--- pve-manager/pve2/bin/Makefile.in 2011-03-03 06:57:36 UTC (rev 5638)
+++ pve-manager/pve2/bin/Makefile.in 2011-03-03 07:14:23 UTC (rev 5639)
@@ -216,6 +216,7 @@
top_srcdir = @top_srcdir@
SUBDIRS = init.d cron test
bin_SCRIPTS = \
+ pvestatd \
pvesh \
pveam \
pvebanner \
@@ -227,6 +228,7 @@
pveperf
man_MANS = \
+ pvestatd.1 \
pvedaemon.1 \
pveversion.1 \
pveperf.1
Modified: pve-manager/pve2/bin/init.d/Makefile.am
===================================================================
--- pve-manager/pve2/bin/init.d/Makefile.am 2011-03-03 06:57:36 UTC (rev 5638)
+++ pve-manager/pve2/bin/init.d/Makefile.am 2011-03-03 07:14:23 UTC (rev 5639)
@@ -3,6 +3,7 @@
initdbin_SCRIPTS = \
pvedaemon \
pvebanner \
+ pvestatd \
pvenetcommit
initdbindir = /etc/init.d/
Modified: pve-manager/pve2/bin/init.d/Makefile.in
===================================================================
--- pve-manager/pve2/bin/init.d/Makefile.in 2011-03-03 06:57:36 UTC (rev 5638)
+++ pve-manager/pve2/bin/init.d/Makefile.in 2011-03-03 07:14:23 UTC (rev 5639)
@@ -174,6 +174,7 @@
initdbin_SCRIPTS = \
pvedaemon \
pvebanner \
+ pvestatd \
pvenetcommit
initdbindir = /etc/init.d/
Added: pve-manager/pve2/bin/init.d/pvestatd
===================================================================
--- pve-manager/pve2/bin/init.d/pvestatd (rev 0)
+++ pve-manager/pve2/bin/init.d/pvestatd 2011-03-03 07:14:23 UTC (rev 5639)
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+### BEGIN INIT INFO
+# Provides: pvestatd
+# Required-Start: $remote_fs $network $syslog pve-cluster
+# Required-Stop: $remote_fs $network $syslog pve-cluster
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: PVE Status Daemon
+### END INIT INFO
+
+. /lib/lsb/init-functions
+
+PATH=/sbin:/bin:/usr/bin:/usr/sbin
+NAME=pvestatd
+DAEMON=/usr/bin/pvestatd
+DESC="PVE Status Daemon"
+
+PIDFILE=/var/run/pvestatd.pid
+
+test -f $DAEMON || exit 0
+
+case "$1" in
+ start)
+ log_daemon_msg "Starting $DESC" "$NAME"
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
+ log_end_msg $?
+ ;;
+ stop)
+ log_daemon_msg "Stopping $DESC" "$NAME"
+ start-stop-daemon --stop --quiet --retry TERM/5/TERM/10/KILL/2 --pidfile $PIDFILE
+ log_end_msg $?
+ ;;
+ reload)
+ log_daemon_msg "Reloading $DESC" "$NAME"
+ if ( [ -e $PIDFILE ] && kill -0 `cat $PIDFILE`) then
+ start-stop-daemon --stop --quiet --pidfile $PIDFILE --signal HUP
+ else
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
+ fi
+ log_end_msg $?
+ ;;
+ restart|force-reload)
+ log_daemon_msg "Restarting $DESC" "$NAME"
+ start-stop-daemon --stop --quiet --retry TERM/5/TERM/10/KILL/2 --pidfile $PIDFILE
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
+ log_end_msg $?
+ ;;
+ *)
+ N=/etc/init.d/$NAME
+ echo "Usage: $N {start|stop|reload|restart|force-reload}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0
Property changes on: pve-manager/pve2/bin/init.d/pvestatd
___________________________________________________________________
Added: svn:executable
+ *
Modified: pve-manager/pve2/bin/pvedaemon
===================================================================
--- pve-manager/pve2/bin/pvedaemon 2011-03-03 06:57:36 UTC (rev 5638)
+++ pve-manager/pve2/bin/pvedaemon 2011-03-03 07:14:23 UTC (rev 5639)
@@ -16,7 +16,7 @@
my $pidfile = "/var/run/pvedaemon.pid";
my $opt_debug;
-initlog ('pvedaemon', 'daemon');
+initlog ('pvedaemon');
if (!GetOptions ('debug' => \$opt_debug)) {
die "usage: $0 [--debug]\n";
Added: pve-manager/pve2/bin/pvestatd
===================================================================
--- pve-manager/pve2/bin/pvestatd (rev 0)
+++ pve-manager/pve2/bin/pvestatd 2011-03-03 07:14:23 UTC (rev 5639)
@@ -0,0 +1,231 @@
+#!/usr/bin/perl -w
+
+use strict;
+use PVE::SafeSyslog;
+use POSIX ":sys_wait_h";
+use Fcntl ':flock';
+use Getopt::Long;
+use Time::HiRes qw (gettimeofday);
+use PVE::Tools;
+use PVE::ProcFSTools;
+
+initlog('pvestatd');
+
+my $opt_debug;
+
+if (!GetOptions ('debug' => \$opt_debug)) {
+ die "USAGE: $0 [--debug]\n";
+}
+
+my $opt_pidfile = "/var/run/pvestatd.pid";
+
+sub lockpidfile {
+ my $pidfile = shift;
+ my $lkfn = "$pidfile.lock";
+
+ if (!open (FLCK, ">>$lkfn")) {
+ my $msg = "can't aquire lock on file '$lkfn' - $!";
+ syslog ('err', $msg);
+ die "ERROR: $msg\n";
+ }
+
+ if (!flock (FLCK, LOCK_EX|LOCK_NB)) {
+ close (FLCK);
+ my $msg = "can't aquire lock '$lkfn' - $!";
+ syslog ('err', $msg);
+ die "ERROR: $msg\n";
+ }
+}
+
+sub writepidfile {
+ my $pidfile = shift;
+
+ if (!open (PIDFH, ">$pidfile")) {
+ my $msg = "can't open pid file '$pidfile' - $!";
+ syslog ('err', $msg);
+ die "ERROR: $msg\n";
+ }
+ print PIDFH "$$\n";
+ close (PIDFH);
+}
+
+# try to get the lock
+lockpidfile($opt_pidfile);
+
+# run in background
+my $spid;
+
+my $restart = $ENV{RESTART_PVESTATD};
+
+if (!$opt_debug) {
+ open STDIN, '</dev/null' || die "can't read /dev/null";
+ open STDOUT, '>/dev/null' || die "can't write /dev/null";
+}
+
+if (!$restart && !$opt_debug) {
+ $spid = fork();
+ if (!defined ($spid)) {
+ my $msg = "can't put server into background - fork failed";
+ syslog('err', $msg);
+ die "ERROR: $msg\n";
+ } elsif ($spid) { #parent
+ exit (0);
+ }
+}
+
+writepidfile($opt_pidfile);
+
+open STDERR, '>&STDOUT' || die "can't close STDERR\n";
+
+sub cleanup {
+ unlink "$opt_pidfile.lock";
+ unlink "$opt_pidfile";
+}
+
+$SIG{INT} = $SIG{TERM} = $SIG{QUIT} = sub {
+ syslog('info' , "server closing");
+
+ $SIG{INT} = 'DEFAULT';
+
+ # wait for children
+ 1 while (waitpid(-1, POSIX::WNOHANG()) > 0);
+
+ cleanup();
+
+ exit (0);
+};
+
+my $reload_config;
+
+if ($restart) {
+ syslog('info' , "restarting server");
+} else {
+ syslog('info' , "starting server");
+}
+
+$SIG{HUP} = sub {
+ $reload_config = 1;
+};
+
+sub update_host_status {
+
+
+}
+
+sub update_qemu_status {
+
+}
+
+sub update_storage_status {
+
+}
+
+sub update_status {
+
+ eval {
+ update_host_status();
+ };
+ my $err = $@;
+ syslog('err', "host status update error: $err") if $err;
+
+ eval {
+ update_qemu_status();
+ };
+ $err = $@;
+ syslog('err', "qemu status update error: $err") if $err;
+
+ eval {
+ update_storage_status();
+ };
+ $err = $@;
+ syslog('err', "storage status update error: $err") if $err;
+}
+
+my $next_update = 0;
+
+# do not update directly after startup, because install scripts
+# have a problem with that
+my $cycle = 0;
+my $updatetime = 60;
+
+my $commandline = [$0, @ARGV];
+
+$0 = "pvestatd";
+
+sub restart_server {
+ my $waittime = shift;
+
+ syslog('info', "server shutdown (restart)");
+
+ $ENV{RESTART_PVESTATD} = 1;
+
+ sleep($waittime) if $waittime; # avoid high server load due to restarts
+
+ exec (@$commandline);
+ exit (-1); # never reached?
+}
+
+for (;;) { # forever
+
+ eval {
+ $next_update = time() + $updatetime;
+
+ my ($ccsec, $cusec) = gettimeofday ();
+ eval {
+ $reload_config = 0;
+ syslog('info', "start status update");
+ update_status() if $cycle;
+ };
+ my $err = $@;
+
+ if ($err) {
+ syslog('err', "status update error: $err");
+ }
+
+ my ($ccsec_end, $cusec_end) = gettimeofday ();
+ my $cptime = ($ccsec_end-$ccsec) + ($cusec_end - $cusec)/1000000;
+
+ syslog('info', sprintf("status update finished (%.2f seconds)", $cptime));
+
+ $cycle++;
+
+ my $mem = PVE::ProcFSTools::read_memory_usage();
+
+ if ($mem->{resident} > (35*1024*1024)) {
+ syslog ('info', "restarting server after $cycle cycles to " .
+ "reduce memory usage (free $mem->{resident} bytes)");
+ restart_server ();
+ }
+
+ while (time < $next_update && !$reload_config) { sleep (1); };
+ };
+
+ my $err = $@;
+
+ if ($err) {
+ syslog ('err', "ERROR: $err");
+ restart_server(5);
+ exit (0);
+ }
+}
+
+exit (0);
+
+__END__
+
+=head1 NAME
+
+pvestatd - PVE Status Daemon
+
+=head1 SYNOPSIS
+
+pvestatd
+
+=head1 DESCRIPTION
+
+Documentation is available at www.proxmox.com
+
+
+
+
+
Property changes on: pve-manager/pve2/bin/pvestatd
___________________________________________________________________
Added: svn:executable
+ *
Modified: pve-manager/pve2/debian/conffiles
===================================================================
--- pve-manager/pve2/debian/conffiles 2011-03-03 06:57:36 UTC (rev 5638)
+++ pve-manager/pve2/debian/conffiles 2011-03-03 07:14:23 UTC (rev 5639)
@@ -1,6 +1,7 @@
/etc/init.d/pvedaemon
/etc/init.d/pvebanner
/etc/init.d/pvenetcommit
+/etc/init.d/pvestatd
/etc/cron.daily/pve
/etc/apache2/sites-available/pve.conf
/etc/vz/conf/ve-pve.auto.conf-sample
Modified: pve-manager/pve2/debian/postinst
===================================================================
--- pve-manager/pve2/debian/postinst 2011-03-03 06:57:36 UTC (rev 5638)
+++ pve-manager/pve2/debian/postinst 2011-03-03 07:14:23 UTC (rev 5639)
@@ -26,6 +26,7 @@
test -e /var/lib/pve-manager/apl-available || cp /usr/share/doc/pve-manager/aplinfo.dat /var/lib/pve-manager/apl-available
update-rc.d pvedaemon defaults 21 >/dev/null 2>&1
+ update-rc.d pvestatd defaults 21 >/dev/null 2>&1
update-rc.d pvebanner defaults 99 >/dev/null 2>&1
update-rc.d pvenetcommit start 15 S . >/dev/null 2>&1
@@ -33,6 +34,7 @@
touch /etc/cron.d/vzdump
test -e /proxmox_install_mode || invoke-rc.d pvedaemon restart
+ test -e /proxmox_install_mode || invoke-rc.d pvestatd restart
a2enmod perl >/dev/null 2>&1
a2enmod ssl >/dev/null 2>&1
Modified: pve-manager/pve2/debian/postrm
===================================================================
--- pve-manager/pve2/debian/postrm 2011-03-03 06:57:36 UTC (rev 5638)
+++ pve-manager/pve2/debian/postrm 2011-03-03 07:14:23 UTC (rev 5639)
@@ -5,6 +5,7 @@
if [ "$1" = purge ]; then
update-rc.d pvedaemon remove >/dev/null 2>&1
+ update-rc.d pvestatd remove >/dev/null 2>&1
update-rc.d pvebanner remove >/dev/null 2>&1
update-rc.d pvenetcommit remove >/dev/null 2>&1
More information about the pve-devel
mailing list