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; ...@@ -24,19 +24,24 @@ use PVE::CLIHandler;
use base qw(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->init_request();
$rpcenv->set_language($ENV{LANG}); $rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam'); $rpcenv->set_user('root@pam');
}
my $upid_exit = sub { my $upid_exit = sub {
my $upid = shift; my $upid = shift;
...@@ -44,8 +49,6 @@ my $upid_exit = sub { ...@@ -44,8 +49,6 @@ my $upid_exit = sub {
exit($status eq 'OK' ? 0 : -1); exit($status eq 'OK' ? 0 : -1);
}; };
my $nodename = PVE::INotify::nodename();
__PACKAGE__->register_method ({ __PACKAGE__->register_method ({
name => 'purge', name => 'purge',
path => 'purge', path => 'purge',
...@@ -169,7 +172,7 @@ my $cmddef = { ...@@ -169,7 +172,7 @@ my $cmddef = {
my $cmd = shift; 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; exit 0;
......
...@@ -34,11 +34,13 @@ my %daemon_options = ( ...@@ -34,11 +34,13 @@ my %daemon_options = (
leave_children_open_on_reload => 1, leave_children_open_on_reload => 1,
); );
# create dir for dtach sockets
mkdir "/var/run/dtach";
my $daemon = __PACKAGE__->new('pvedaemon', $cmdline, %daemon_options); my $daemon = __PACKAGE__->new('pvedaemon', $cmdline, %daemon_options);
sub prepare {
# create dir for dtach sockets
mkdir "/var/run/dtach";
}
sub init { sub init {
my ($self) = @_; my ($self) = @_;
...@@ -83,7 +85,7 @@ my $cmddef = { ...@@ -83,7 +85,7 @@ my $cmddef = {
my $cmd = shift; 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); exit (0);
......
...@@ -51,15 +51,17 @@ my %daemon_options = ( ...@@ -51,15 +51,17 @@ my %daemon_options = (
pidfile => '/var/run/pveproxy/pveproxy.pid', pidfile => '/var/run/pveproxy/pveproxy.pid',
); );
my $rundir="/var/run/pveproxy"; my $daemon = __PACKAGE__->new('pveproxy', $cmdline, %daemon_options);
if (mkdir($rundir, 0700)) { # only works at first start if we are root)
my $gid = getgrnam('www-data') || die "getgrnam failed - $!\n"; sub prepare {
my $uid = getpwnam('www-data') || die "getpwnam failed - $!\n"; my $rundir="/var/run/pveproxy";
chown($uid, $gid, $rundir); 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 { sub add_dirs {
my ($result_hash, $alias, $subdir) = @_; my ($result_hash, $alias, $subdir) = @_;
...@@ -160,7 +162,7 @@ my $cmddef = { ...@@ -160,7 +162,7 @@ my $cmddef = {
my $cmd = shift; 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); exit (0);
......
...@@ -27,15 +27,18 @@ my $cmdline = [$0, @ARGV]; ...@@ -27,15 +27,18 @@ my $cmdline = [$0, @ARGV];
my %daemon_options = (restart_on_error => 5, stop_wait_time => 5); my %daemon_options = (restart_on_error => 5, stop_wait_time => 5);
my $daemon = __PACKAGE__->new('pvestatd', $cmdline, %daemon_options); 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->init_request();
$rpcenv->set_language($ENV{LANG}); $rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam'); $rpcenv->set_user('root@pam');
my $nodename = PVE::INotify::nodename(); $restart_request = 0;
my $restart_request = 0; }
sub init { sub init {
my ($self) = @_; my ($self) = @_;
...@@ -354,7 +357,7 @@ my $cmddef = { ...@@ -354,7 +357,7 @@ my $cmddef = {
my $cmd = shift; 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); exit (0);
......
...@@ -13,22 +13,23 @@ use PVE::API2::Subscription; ...@@ -13,22 +13,23 @@ use PVE::API2::Subscription;
use base qw(PVE::CLIHandler); use base qw(PVE::CLIHandler);
$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin'; my $nodename = PVE::INotify::nodename();
initlog('pvesubscription');
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(); PVE::INotify::inotify_init();
$rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam');
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 = { my $cmddef = {
...@@ -45,7 +46,7 @@ my $cmddef = { ...@@ -45,7 +46,7 @@ my $cmddef = {
my $cmd = shift; 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; exit 0;
......
...@@ -40,15 +40,17 @@ my %daemon_options = ( ...@@ -40,15 +40,17 @@ my %daemon_options = (
pidfile => '/var/run/pveproxy/spiceproxy.pid', 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); 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 { sub init {
my ($self) = @_; my ($self) = @_;
...@@ -101,7 +103,7 @@ my $cmddef = { ...@@ -101,7 +103,7 @@ my $cmddef = {
my $cmd = shift; 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); 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