#!/usr/bin/perl -T

$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';

delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};  

use strict;
use warnings;

use PVE::SafeSyslog;
use PVE::Service::pveproxy;

$SIG{'__WARN__'} = sub {
    my $err = $@;
    my $t = $_[0];
    chomp $t;
    print STDERR "$t\n";
    syslog('warning', "%s", $t);
    $@ = $err;
};

my $prepare = sub {
    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);
    }
};

PVE::Service::pveproxy->run_cli_handler(prepare => $prepare);