mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-04-29 18:37:51 +00:00
pvedaemon: use PVE::Daemon
This commit is contained in:
parent
2560c968d1
commit
6669b51cd2
@ -46,6 +46,9 @@ all: ${MANS} pvemailforward
|
|||||||
pvestatd.1.pod: pvestatd
|
pvestatd.1.pod: pvestatd
|
||||||
perl -I.. ./pvestatd printmanpod >$@
|
perl -I.. ./pvestatd printmanpod >$@
|
||||||
|
|
||||||
|
pvedaemon.1.pod: pvedaemon
|
||||||
|
perl -I.. -T ./pvedaemon printmanpod >$@
|
||||||
|
|
||||||
pveproxy.1.pod: pveproxy
|
pveproxy.1.pod: pveproxy
|
||||||
perl -I.. -T ./pveproxy printmanpod >$@
|
perl -I.. -T ./pveproxy printmanpod >$@
|
||||||
|
|
||||||
|
@ -25,33 +25,23 @@ export LC_ALL="C"
|
|||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
log_daemon_msg "Starting $DESC" "$NAME"
|
log_daemon_msg "Starting $DESC" "$NAME"
|
||||||
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
|
$DAEMON start
|
||||||
log_end_msg $?
|
log_end_msg $?
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
log_daemon_msg "Stopping $DESC" "$NAME"
|
log_daemon_msg "Stopping $DESC" "$NAME"
|
||||||
start-stop-daemon --stop --quiet --retry TERM/2/TERM/15/KILL/2 --pidfile $PIDFILE
|
$DAEMON stop
|
||||||
log_end_msg $?
|
log_end_msg $?
|
||||||
;;
|
;;
|
||||||
reload)
|
restart|reload|force-reload)
|
||||||
log_daemon_msg "Reloading $DESC" "$NAME"
|
|
||||||
if ( [ -e $PIDFILE ] && kill -0 `cat $PIDFILE`) then
|
|
||||||
start-stop-daemon --stop --signal HUP --pidfile $PIDFILE
|
|
||||||
else
|
|
||||||
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
|
|
||||||
fi
|
|
||||||
log_end_msg $?
|
|
||||||
;;
|
|
||||||
restart|force-reload)
|
|
||||||
log_daemon_msg "Restarting $DESC" "$NAME"
|
log_daemon_msg "Restarting $DESC" "$NAME"
|
||||||
start-stop-daemon --stop --quiet --retry TERM/2/TERM/15/KILL/2 --pidfile $PIDFILE
|
$DAEMON restart
|
||||||
sleep 2
|
|
||||||
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
|
log_end_msg $?
|
||||||
log_end_msg $?
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
N=/etc/init.d/$NAME
|
N=/etc/init.d/$NAME
|
||||||
echo "Usage: $N {start|stop|restart|force-reload}"
|
echo "Usage: $N {start|stop|restart|reload|force-reload}"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
157
bin/pvedaemon
157
bin/pvedaemon
@ -6,109 +6,83 @@ delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Getopt::Long;
|
|
||||||
use POSIX ":sys_wait_h";
|
|
||||||
use Socket;
|
|
||||||
use PVE::SafeSyslog;
|
use PVE::SafeSyslog;
|
||||||
use PVE::APIDaemon;
|
use PVE::Daemon;
|
||||||
use PVE::API2;
|
use PVE::API2;
|
||||||
use PVE::API2::Formatter::Standard;
|
use PVE::API2::Formatter::Standard;
|
||||||
use PVE::API2::Formatter::HTML;
|
use PVE::API2::Formatter::HTML;
|
||||||
|
|
||||||
my $pidfile = "/var/run/pvedaemon.pid";
|
use base qw(PVE::Daemon);
|
||||||
my $lockfile = "/var/lock/pvedaemon.lck";
|
|
||||||
|
|
||||||
my $opt_debug;
|
|
||||||
|
|
||||||
initlog ('pvedaemon');
|
|
||||||
|
|
||||||
if (!GetOptions ('debug' => \$opt_debug)) {
|
|
||||||
die "usage: $0 [--debug]\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
$SIG{'__WARN__'} = sub {
|
$SIG{'__WARN__'} = sub {
|
||||||
my $err = $@;
|
my $err = $@;
|
||||||
my $t = $_[0];
|
my $t = $_[0];
|
||||||
chomp $t;
|
chomp $t;
|
||||||
syslog('warning', "WARNING: %s", $t);
|
print STDERR "$t\n";
|
||||||
|
syslog('warning', "%s", $t);
|
||||||
$@ = $err;
|
$@ = $err;
|
||||||
};
|
};
|
||||||
|
|
||||||
$0 = "pvedaemon";
|
my $cmdline = [$0, @ARGV];
|
||||||
|
|
||||||
|
my %daemon_options = (
|
||||||
|
max_workers => 3,
|
||||||
|
restart_on_error => 5,
|
||||||
|
stop_wait_time => 15,
|
||||||
|
leave_children_open_on_reload => 1,
|
||||||
|
);
|
||||||
|
|
||||||
# create dir for dtach sockets
|
# create dir for dtach sockets
|
||||||
mkdir "/var/run/dtach";
|
mkdir "/var/run/dtach";
|
||||||
|
|
||||||
my $cpid;
|
my $daemon = __PACKAGE__->new('pvedaemon', $cmdline, %daemon_options);
|
||||||
my $daemon;
|
|
||||||
eval {
|
sub init {
|
||||||
$daemon = PVE::APIDaemon->new(
|
my ($self) = @_;
|
||||||
|
|
||||||
|
my $accept_lock_fn = "/var/lock/pvedaemon.lck";
|
||||||
|
|
||||||
|
my $lockfh = IO::File->new(">>${accept_lock_fn}") ||
|
||||||
|
die "unable to open lock file '${accept_lock_fn}' - $!\n";
|
||||||
|
|
||||||
|
my $socket = $self->create_reusable_socket(85, '127.0.0.1');
|
||||||
|
|
||||||
|
$self->{server_config} = {
|
||||||
base_handler_class => 'PVE::API2',
|
base_handler_class => 'PVE::API2',
|
||||||
host => "127.0.0.1",
|
|
||||||
port => 85,
|
|
||||||
trusted_env => 1, # partly trusted, because only local programs can connect
|
|
||||||
lockfile => $lockfile,
|
|
||||||
debug => $opt_debug,
|
|
||||||
keep_alive => 100,
|
keep_alive => 100,
|
||||||
max_conn => 500,
|
max_conn => 500,
|
||||||
max_requests => 1000);
|
max_requests => 1000,
|
||||||
|
lockfile => $accept_lock_fn,
|
||||||
|
socket => $socket,
|
||||||
|
lockfh => $lockfh,
|
||||||
|
debug => $self->{debug},
|
||||||
|
trusted_env => 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
sub run {
|
||||||
|
my ($self) = @_;
|
||||||
|
|
||||||
|
my $server = PVE::HTTPServer->new(%{$self->{server_config}});
|
||||||
|
$server->run();
|
||||||
|
}
|
||||||
|
|
||||||
|
$daemon->register_start_command();
|
||||||
|
$daemon->register_restart_command(1);
|
||||||
|
$daemon->register_stop_command();
|
||||||
|
$daemon->register_status_command();
|
||||||
|
|
||||||
|
my $cmddef = {
|
||||||
|
start => [ __PACKAGE__, 'start', []],
|
||||||
|
restart => [ __PACKAGE__, 'restart', []],
|
||||||
|
stop => [ __PACKAGE__, 'stop', []],
|
||||||
|
status => [ __PACKAGE__, 'status', [], undef, sub { print shift . "\n";} ],
|
||||||
};
|
};
|
||||||
|
|
||||||
my $err = $@;
|
my $cmd = shift;
|
||||||
|
|
||||||
if ($err) {
|
PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0);
|
||||||
syslog ('err' , "unable to start server: $err");
|
|
||||||
print STDERR $err;
|
|
||||||
exit (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($opt_debug || !($cpid = fork ())) {
|
|
||||||
|
|
||||||
$SIG{PIPE} = 'IGNORE';
|
|
||||||
$SIG{INT} = 'IGNORE' if !$opt_debug;
|
|
||||||
|
|
||||||
$SIG{TERM} = $SIG{QUIT} = sub {
|
|
||||||
syslog ('info' , "server closing");
|
|
||||||
|
|
||||||
$SIG{INT} = 'DEFAULT';
|
|
||||||
|
|
||||||
unlink "$pidfile";
|
|
||||||
|
|
||||||
exit (0);
|
|
||||||
};
|
|
||||||
|
|
||||||
syslog ('info' , "starting server");
|
|
||||||
|
|
||||||
if (!$opt_debug) {
|
|
||||||
# redirect STDIN/STDOUT/SDTERR to /dev/null
|
|
||||||
open STDIN, '</dev/null' || die "can't read /dev/null [$!]";
|
|
||||||
open STDOUT, '>/dev/null' || die "can't write /dev/null [$!]";
|
|
||||||
open STDERR, '>&STDOUT' || die "can't open STDERR to STDOUT [$!]";
|
|
||||||
}
|
|
||||||
|
|
||||||
POSIX::setsid();
|
|
||||||
|
|
||||||
system ("echo > /var/lib/pve-manager/vmops"); # init vmops file
|
|
||||||
|
|
||||||
eval {
|
|
||||||
$daemon->start_server();
|
|
||||||
};
|
|
||||||
my $err = $@;
|
|
||||||
|
|
||||||
if ($err) {
|
|
||||||
syslog ('err' , "unexpected server error: $err");
|
|
||||||
print STDERR $err if $opt_debug;
|
|
||||||
exit (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
open (PIDFILE, ">$pidfile") ||
|
|
||||||
die "cant write '$pidfile' - $! :ERROR";
|
|
||||||
print PIDFILE "$cpid\n";
|
|
||||||
close (PIDFILE) ||
|
|
||||||
die "cant write '$pidfile' - $! :ERROR";
|
|
||||||
}
|
|
||||||
|
|
||||||
exit (0);
|
exit (0);
|
||||||
|
|
||||||
@ -118,9 +92,7 @@ __END__
|
|||||||
|
|
||||||
pvedaemon - the PVE configuration server
|
pvedaemon - the PVE configuration server
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
=include synopsis
|
||||||
|
|
||||||
pvedaemon [--debug]
|
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
@ -128,21 +100,4 @@ All configuration is done using this Server. The Server only
|
|||||||
listens to a local address 127.0.0.1 port 85 for security
|
listens to a local address 127.0.0.1 port 85 for security
|
||||||
reasons.
|
reasons.
|
||||||
|
|
||||||
=head1 COPYRIGHT AND DISCLAIMER
|
=include pve_copyright
|
||||||
|
|
||||||
Copyright (C) 2007-2013 Proxmox Server Solutions GmbH
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
|
||||||
under the terms of the GNU Affero General Public License as published
|
|
||||||
by the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but
|
|
||||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public
|
|
||||||
License along with this program. If not, see
|
|
||||||
<http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user