Commit e7206545 authored by Wolfgang Bumiller's avatar Wolfgang Bumiller Committed by Dietmar Maurer

move preparations into prepare()

Moving some preparation code found at the top level of some binaries
into a prepare() sub.
parent 75b3110d
......@@ -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();
sub prepare {
$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
initlog ('pveceph');
initlog ('pveceph');
die "please run as root\n" if $> != 0;
die "please run as root\n" if $> != 0;
PVE::INotify::inotify_init();
PVE::INotify::inotify_init();
my $rpcenv = PVE::RPCEnvironment->init('cli');
my $rpcenv = PVE::RPCEnvironment->init('cli');
$rpcenv->init_request();
$rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam');
$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;
......
......@@ -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);
......
......@@ -51,15 +51,17 @@ 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);
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);
}
}
my $daemon = __PACKAGE__->new('pveproxy', $cmdline, %daemon_options);
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);
......
......@@ -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 $nodename = PVE::INotify::nodename();
my $restart_request;
my $rpcenv = PVE::RPCEnvironment->init('cli');
sub prepare {
my $rpcenv = PVE::RPCEnvironment->init('cli');
$rpcenv->init_request();
$rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam');
$rpcenv->init_request();
$rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam');
my $nodename = PVE::INotify::nodename();
my $restart_request = 0;
$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);
......
......@@ -13,22 +13,23 @@ use PVE::API2::Subscription;
use base qw(PVE::CLIHandler);
$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
initlog('pvesubscription');
my $nodename = PVE::INotify::nodename();
die "please run as root\n" if $> != 0;
sub prepare {
$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
PVE::INotify::inotify_init();
initlog('pvesubscription');
my $rpcenv = PVE::RPCEnvironment->init('cli');
die "please run as root\n" if $> != 0;
$rpcenv->init_request();
$rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam');
PVE::INotify::inotify_init();
my $nodename = PVE::INotify::nodename();
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;
......
......@@ -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);
......
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