Commit bd1957bc authored by Dietmar Maurer's avatar Dietmar Maurer

spiceproxy: use PVE::Daemon

parent f76dbc2d
...@@ -46,6 +46,9 @@ all: ${MANS} pvemailforward ...@@ -46,6 +46,9 @@ all: ${MANS} pvemailforward
pvestatd.1.pod: pvestatd pvestatd.1.pod: pvestatd
perl -I.. ./pvestatd printmanpod >$@ perl -I.. ./pvestatd printmanpod >$@
spiceproxy.1.pod: spiceproxy
perl -I.. -T ./spiceproxy printmanpod >$@
pvectl.1.pod: pvectl pvectl.1.pod: pvectl
perl -I.. ./pvectl printmanpod >$@ perl -I.. ./pvectl printmanpod >$@
......
...@@ -35,37 +35,31 @@ if [ -f /etc/default/$NAME ] ; then ...@@ -35,37 +35,31 @@ if [ -f /etc/default/$NAME ] ; then
fi fi
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_OPTS} $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) reload)
log_daemon_msg "Reloading $DESC" "$NAME" log_daemon_msg "Reloading $DESC" "$NAME"
if ( [ -e $PIDFILE ] && kill -0 `cat $PIDFILE`) then $DAEMON reload
start-stop-daemon --stop --signal HUP --pidfile $PIDFILE log_end_msg $?
else ;;
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- ${DAEMON_OPTS} restart|force-reload)
fi log_daemon_msg "Restarting $DESC" "$NAME"
log_end_msg $? $DAEMON restart
;; log_end_msg $?
restart|force-reload) ;;
log_daemon_msg "Restarting $DESC" "$NAME" *)
start-stop-daemon --stop --quiet --retry TERM/2/TERM/15/KILL/2 --pidfile $PIDFILE N=/etc/init.d/$NAME
sleep 2 echo "Usage: $N {start|stop|restart|force-reload}"
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- ${DAEMON_OPTS} exit 1
log_end_msg $? ;;
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}"
exit 1
;;
esac esac
exit 0 exit 0
...@@ -11,31 +11,19 @@ delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; ...@@ -11,31 +11,19 @@ delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long;
use PVE::SafeSyslog; use PVE::SafeSyslog;
use PVE::Daemon;
use PVE::APIDaemon; use PVE::APIDaemon;
use PVE::API2; use PVE::API2;
my $pidfile = "/var/run/pveproxy/spiceproxy.pid"; use base qw(PVE::Daemon);
my $lockfile = "/var/lock/spiceproxy.lck";
my $opt_debug;
initlog ('spiceproxy');
if (!GetOptions ('debug' => \$opt_debug)) { my $cmdline = [$0, @ARGV];
die "usage: $0 [--debug]\n";
}
$SIG{'__WARN__'} = sub { my %daemon_options = (restart_on_error => 5, stop_wait_time => 15, run_dir => '/var/run/pveproxy');
my $err = $@;
my $t = $_[0];
chomp $t;
syslog('warning', "WARNING: %s", $t);
$@ = $err;
};
$0 = "spiceproxy"; my $daemon = __PACKAGE__->new('spiceproxy', $cmdline, %daemon_options);
my $gid = getgrnam('www-data') || die "getgrnam failed - $!\n"; my $gid = getgrnam('www-data') || die "getgrnam failed - $!\n";
POSIX::setgid($gid) || die "setgid $gid failed - $!\n"; POSIX::setgid($gid) || die "setgid $gid failed - $!\n";
...@@ -46,81 +34,57 @@ POSIX::setuid($uid) || die "setuid $uid failed - $!\n"; ...@@ -46,81 +34,57 @@ POSIX::setuid($uid) || die "setuid $uid failed - $!\n";
# just to be sure # just to be sure
die "detected strange uid/gid\n" if !($UID == $uid && $EUID == $uid && $GID eq "$gid $gid" && $EGID eq "$gid $gid"); die "detected strange uid/gid\n" if !($UID == $uid && $EUID == $uid && $GID eq "$gid $gid" && $EGID eq "$gid $gid");
# we use same ALLOW/DENY/POLICY as pveproxy sub init {
my $proxyconf = PVE::APIDaemon::read_proxy_config(); my ($self) = @_;
# we use same ALLOW/DENY/POLICY as pveproxy
my $proxyconf = PVE::APIDaemon::read_proxy_config();
my $cpid; $self->{api_daemon} = PVE::APIDaemon->new(
my $daemon;
eval {
$daemon = PVE::APIDaemon->new(
base_handler_class => 'PVE::API2', base_handler_class => 'PVE::API2',
port => 3128, port => 3128,
keep_alive => 0, keep_alive => 0,
max_workers => 1, # do we need more? max_workers => 1, # do we need more?
max_conn => 500, max_conn => 500,
lockfile => $lockfile, lockfile => "/var/lock/spiceproxy.lck",
debug => $opt_debug, debug => $self->{debug},
spiceproxy => 1, spiceproxy => 1,
logfile => '/var/log/pveproxy/access.log', logfile => '/var/log/pveproxy/access.log',
allow_from => $proxyconf->{ALLOW_FROM}, allow_from => $proxyconf->{ALLOW_FROM},
deny_from => $proxyconf->{DENY_FROM}, deny_from => $proxyconf->{DENY_FROM},
policy => $proxyconf->{POLICY}, policy => $proxyconf->{POLICY},
); );
};
my $err = $@;
if ($err) {
syslog ('err' , "unable to start server: $err");
print STDERR $err;
exit (-1);
} }
if ($opt_debug || !($cpid = fork ())) { sub shutdown {
my ($self) = @_;
$SIG{PIPE} = 'IGNORE';
$SIG{INT} = 'IGNORE' if !$opt_debug;
$SIG{TERM} = $SIG{QUIT} = sub {
syslog ('info' , "server closing");
$SIG{INT} = 'DEFAULT';
unlink "$pidfile"; $self->exit_daemon(0);
}
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(); sub run {
my ($self) = @_;
eval {
$daemon->start_server(); $self->{api_daemon}->start_server();
}; }
my $err = $@;
if ($err) { $daemon->register_start_command(__PACKAGE__);
syslog ('err' , "unexpected server error: $err"); $daemon->register_restart_command(__PACKAGE__, 0);
print STDERR $err if $opt_debug; $daemon->register_reload_command(__PACKAGE__);
exit (-1); $daemon->register_stop_command(__PACKAGE__);
} $daemon->register_status_command(__PACKAGE__);
my $cmddef = {
start => [ __PACKAGE__, 'start', []],
restart => [ __PACKAGE__, 'restart', []],
reload => [ __PACKAGE__, 'reload', []],
stop => [ __PACKAGE__, 'stop', []],
status => [ __PACKAGE__, 'status', [], undef, sub { print shift . "\n";} ],
};
} else { my $cmd = shift;
open (PIDFILE, ">$pidfile") || PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0);
die "cant write '$pidfile' - $! :ERROR";
print PIDFILE "$cpid\n";
close (PIDFILE) ||
die "cant write '$pidfile' - $! :ERROR";
}
exit (0); exit (0);
...@@ -132,7 +96,7 @@ spiceproxy - SPICE proxy server for Proxmox VE ...@@ -132,7 +96,7 @@ spiceproxy - SPICE proxy server for Proxmox VE
=head1 SYNOPSIS =head1 SYNOPSIS
spiceproxy [--debug] =include synopsis
=head1 DESCRIPTION =head1 DESCRIPTION
...@@ -147,21 +111,4 @@ from file /etc/default/pveproxy (see 'pveproxy' for details). ...@@ -147,21 +111,4 @@ from file /etc/default/pveproxy (see 'pveproxy' for details).
/etc/default/pveproxy /etc/default/pveproxy
=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/>.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment