9   $dir    =  Cwd::getcwd() . '/' . $dir unless $dir =~ m|^/|;
 
  12   chdir($dir) || die "Cannot change directory to ${dir}\n";
 
  14   unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
 
  15   push    @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
 
  18 use CGI qw( -no_xhtml);
 
  23 use English qw(-no_match_vars);
 
  24 use POSIX qw(setuid setgid);
 
  26 use SL::DB::BackgroundJob;
 
  27 use SL::BackgroundJob::ALL;
 
  29 use SL::Helper::DateTime;
 
  30 use SL::InstanceConfiguration;
 
  38   my $login = $lx_office_conf{task_server}->{login};
 
  42   $::lxdebug       = LXDebug->new;
 
  43   $::locale        = Locale->new($::lx_office_conf{system}->{language});
 
  45   $::auth          = SL::Auth->new;
 
  46   $::instance_conf = SL::InstanceConfiguration->new;
 
  47   $::request       = { cgi => CGI->new({}) };
 
  49   die 'cannot reach auth db'               unless $::auth->session_tables_present;
 
  51   $::auth->restore_session;
 
  53   require "bin/mozilla/common.pl";
 
  55   die "cannot find user $login"            unless %::myconfig = $::auth->read_user(login => $login);
 
  56   die "cannot find locale for user $login" unless $::locale   = Locale->new('de');
 
  60   my $user = $lx_office_conf{task_server}->{run_as};
 
  64   while (my @details = getpwent()) {
 
  65     next unless $details[0] eq $user;
 
  66     ($uid, $gid) = @details[2, 3];
 
  72     print "Error: Cannot drop privileges to ${user}: user does not exist\n";
 
  77     print "Error: Cannot drop group privileges to ${user} (group ID $gid): $!\n";
 
  82     print "Error: Cannot drop user privileges to ${user} (user ID $uid): $!\n";
 
  90   SL::LxOfficeConf->read($self->{configfile});
 
  92   die "Missing section [task_server] in config file"                unless $lx_office_conf{task_server};
 
  93   die "Missing key 'login' in section [task_server] in config file" unless $lx_office_conf{task_server}->{login};
 
 104       $::lxdebug->message(0, "Retrieving jobs") if $lx_office_conf{task_server}->{debug};
 
 106       my $jobs = SL::DB::Manager::BackgroundJob->get_all_need_to_run;
 
 108       $::lxdebug->message(0, "  Found: " . join(' ', map { $_->package_name } @{ $jobs })) if $lx_office_conf{task_server}->{debug} && @{ $jobs };
 
 110       foreach my $job (@{ $jobs }) {
 
 111         # Provide fresh global variables in case legacy code modifies
 
 113         $::locale = Locale->new($::lx_office_conf{system}->{language});
 
 122     if ($lx_office_conf{task_server}->{debug}) {
 
 123       $::lxdebug->message(0, "Exception during execution: ${EVAL_ERROR}") if !$ok;
 
 124       $::lxdebug->message(0, "Sleeping");
 
 127     my $seconds = 60 - (localtime)[0];
 
 129       local $SIG{'ALRM'} = sub {
 
 130         $::lxdebug->message(0, "Got woken up by SIGALRM") if $lx_office_conf{task_server}->{debug};
 
 133       sleep($seconds < 30 ? $seconds + 60 : $seconds);
 
 136       die $@ unless $@ eq "Alarm!\n";
 
 142 my $pidbase = "${cwd}/users/pid";
 
 144 mkdir($pidbase) if !-d $pidbase;
 
 146 my $file = -f "${cwd}/config/lx_office.conf" ? "${cwd}/config/lx_office.conf" : "${cwd}/config/lx_office.conf.default";
 
 147 newdaemon(configfile => $file,
 
 148           progname   => 'kivitendo-task-server',
 
 149           pidbase    => "${pidbase}/",