move preparations into prepare()

Moving some preparation code found at the top level of some binaries
into a prepare() sub.
This commit is contained in:
Wolfgang Bumiller 2015-05-29 15:56:07 +02:00 committed by Dietmar Maurer
parent 5289a1b81a
commit 98ac92f039
6 changed files with 68 additions and 55 deletions

View File

@ -24,19 +24,24 @@ use PVE::CLIHandler;
use base qw(PVE::CLIHandler);
$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
my $cmddef;
my $nodename = PVE::INotify::nodename();
initlog ('pveceph');
sub prepare {
$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
die "please run as root\n" if $> != 0;
initlog ('pveceph');
PVE::INotify::inotify_init();
die "please run as root\n" if $> != 0;
my $rpcenv = PVE::RPCEnvironment->init('cli');
PVE::INotify::inotify_init();
$rpcenv->init_request();
$rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam');
my $rpcenv = PVE::RPCEnvironment->init('cli');
$rpcenv->init_request();
$rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam');
}
my $upid_exit = sub {
my $upid = shift;
@ -44,8 +49,6 @@ my $upid_exit = sub {
exit($status eq 'OK' ? 0 : -1);
};
my $nodename = PVE::INotify::nodename();
__PACKAGE__->register_method ({
name => 'purge',
path => 'purge',
@ -169,7 +172,7 @@ my $cmddef = {
my $cmd = shift;
PVE::CLIHandler::handle_cmd($cmddef, "pveceph", $cmd, \@ARGV, undef, $0);
PVE::CLIHandler::handle_cmd($cmddef, "pveceph", $cmd, \@ARGV, undef, $0, \&prepare);
exit 0;

View File

@ -34,11 +34,13 @@ my %daemon_options = (
leave_children_open_on_reload => 1,
);
# create dir for dtach sockets
mkdir "/var/run/dtach";
my $daemon = __PACKAGE__->new('pvedaemon', $cmdline, %daemon_options);
sub prepare {
# create dir for dtach sockets
mkdir "/var/run/dtach";
}
sub init {
my ($self) = @_;
@ -83,7 +85,7 @@ my $cmddef = {
my $cmd = shift;
PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0);
PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0, \&prepare);
exit (0);

View File

@ -51,14 +51,16 @@ my %daemon_options = (
pidfile => '/var/run/pveproxy/pveproxy.pid',
);
my $rundir="/var/run/pveproxy";
if (mkdir($rundir, 0700)) { # only works at first start if we are root)
my $gid = getgrnam('www-data') || die "getgrnam failed - $!\n";
my $uid = getpwnam('www-data') || die "getpwnam failed - $!\n";
chown($uid, $gid, $rundir);
}
my $daemon = __PACKAGE__->new('pveproxy', $cmdline, %daemon_options);
my $daemon = __PACKAGE__->new('pveproxy', $cmdline, %daemon_options);
sub prepare {
my $rundir="/var/run/pveproxy";
if (mkdir($rundir, 0700)) { # only works at first start if we are root)
my $gid = getgrnam('www-data') || die "getgrnam failed - $!\n";
my $uid = getpwnam('www-data') || die "getpwnam failed - $!\n";
chown($uid, $gid, $rundir);
}
}
sub add_dirs {
my ($result_hash, $alias, $subdir) = @_;
@ -160,7 +162,7 @@ my $cmddef = {
my $cmd = shift;
PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0);
PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0, \&prepare);
exit (0);

View File

@ -27,15 +27,18 @@ my $cmdline = [$0, @ARGV];
my %daemon_options = (restart_on_error => 5, stop_wait_time => 5);
my $daemon = __PACKAGE__->new('pvestatd', $cmdline, %daemon_options);
my $rpcenv = PVE::RPCEnvironment->init('cli');
$rpcenv->init_request();
$rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam');
my $nodename = PVE::INotify::nodename();
my $restart_request = 0;
my $restart_request;
sub prepare {
my $rpcenv = PVE::RPCEnvironment->init('cli');
$rpcenv->init_request();
$rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam');
$restart_request = 0;
}
sub init {
my ($self) = @_;
@ -354,7 +357,7 @@ my $cmddef = {
my $cmd = shift;
PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0);
PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0, \&prepare);
exit (0);

View File

@ -13,22 +13,23 @@ use PVE::API2::Subscription;
use base qw(PVE::CLIHandler);
$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
initlog('pvesubscription');
die "please run as root\n" if $> != 0;
PVE::INotify::inotify_init();
my $rpcenv = PVE::RPCEnvironment->init('cli');
$rpcenv->init_request();
$rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam');
my $nodename = PVE::INotify::nodename();
sub prepare {
$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
initlog('pvesubscription');
die "please run as root\n" if $> != 0;
PVE::INotify::inotify_init();
my $rpcenv = PVE::RPCEnvironment->init('cli');
$rpcenv->init_request();
$rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam');
}
my $cmddef = {
@ -45,7 +46,7 @@ my $cmddef = {
my $cmd = shift;
PVE::CLIHandler::handle_cmd($cmddef, "pvesubscription", $cmd, \@ARGV, undef, $0);
PVE::CLIHandler::handle_cmd($cmddef, "pvesubscription", $cmd, \@ARGV, undef, $0, \&prepare);
exit 0;

View File

@ -40,15 +40,17 @@ my %daemon_options = (
pidfile => '/var/run/pveproxy/spiceproxy.pid',
);
my $rundir="/var/run/pveproxy";
if (mkdir($rundir, 0700)) { # only works at first start if we are root)
my $gid = getgrnam('www-data') || die "getgrnam failed - $!\n";
my $uid = getpwnam('www-data') || die "getpwnam failed - $!\n";
chown($uid, $gid, $rundir);
}
my $daemon = __PACKAGE__->new('spiceproxy', $cmdline, %daemon_options);
sub prepare {
my $rundir="/var/run/pveproxy";
if (mkdir($rundir, 0700)) { # only works at first start if we are root)
my $gid = getgrnam('www-data') || die "getgrnam failed - $!\n";
my $uid = getpwnam('www-data') || die "getpwnam failed - $!\n";
chown($uid, $gid, $rundir);
}
}
sub init {
my ($self) = @_;
@ -101,7 +103,7 @@ my $cmddef = {
my $cmd = shift;
PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0);
PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0, \&prepare);
exit (0);