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);
24 use English qw(-no_match_vars);
25 use POSIX qw(setuid setgid);
27 use SL::DB::BackgroundJob;
28 use SL::BackgroundJob::ALL;
30 use SL::Helper::DateTime;
36 # this is a cleaned up version of am.pl
37 # it lacks redirection, some html setup and most of the authentication process.
38 # it is assumed that anyone with physical access and execution rights on this script
39 # won't be hindered by authentication anyway.
41 my $login = $lx_office_conf{task_server}->{login};
45 eval { require "config/lx-erp.conf"; 1; } or die $EVAL_ERROR;
46 eval { require "config/lx-erp-local.conf"; 1; } or die $EVAL_ERROR if -f "config/lx-erp-local.conf";
48 $::lxdebug = LXDebug->new;
49 $::locale = Locale->new($::lx_office_conf{system}->{language});
50 $::cgi = CGI->new qw();
52 $::auth = SL::Auth->new;
54 die 'cannot reach auth db' unless $::auth->session_tables_present;
56 $::auth->restore_session;
58 require "bin/mozilla/common.pl";
60 die "cannot find user $login" unless %::myconfig = $::auth->read_user($login);
61 die "cannot find locale for user $login" unless $::locale = Locale->new('de');
65 my $user = $lx_office_conf{task_server}->{run_as};
69 while (my @details = getpwent()) {
70 next unless $details[0] eq $user;
71 ($uid, $gid) = @details[2, 3];
77 print "Error: Cannot drop privileges to ${user}: user does not exist\n";
82 print "Error: Cannot drop group privileges to ${user} (group ID $gid): $!\n";
87 print "Error: Cannot drop user privileges to ${user} (user ID $uid): $!\n";
95 read_config $self->{configfile} => %lx_office_conf;
97 die "Missing section [task_server] in config file" unless $lx_office_conf{task_server};
98 die "Missing key 'login' in section [task_server] in config file" unless $lx_office_conf{task_server}->{login};
109 $::lxdebug->message(0, "Retrieving jobs") if $lx_office_conf{task_server}->{debug};
111 my $jobs = SL::DB::Manager::BackgroundJob->get_all_need_to_run;
113 $::lxdebug->message(0, " Found: " . join(' ', map { $_->package_name } @{ $jobs })) if $lx_office_conf{task_server}->{debug} && @{ $jobs };
115 foreach my $job (@{ $jobs }) {
116 # Provide fresh global variables in case legacy code modifies
118 $::locale = Locale->new($::lx_office_conf{system}->{language});
127 if ($lx_office_conf{task_server}->{debug}) {
128 $::lxdebug->message(0, "Exception during execution: ${EVAL_ERROR}") if !$ok;
129 $::lxdebug->message(0, "Sleeping");
132 my $seconds = 60 - (localtime)[0];
133 sleep($seconds < 30 ? $seconds + 60 : $seconds);
138 my $pidbase = "${cwd}/users/pid";
140 mkdir($pidbase) if !-d $pidbase;
142 newdaemon(configfile => "${cwd}/config/lx_office.conf",
143 progname => 'lx-office-task-server',
144 pidbase => "${pidbase}/",