6 unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
7 push @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
10 use CGI qw( -no_xhtml);
16 use English qw(-no_match_vars);
17 use POSIX qw(setuid setgid);
19 use SL::DB::BackgroundJob;
20 use SL::BackgroundJob::ALL;
22 use SL::Helper::DateTime;
28 # this is a cleaned up version of am.pl
29 # it lacks redirection, some html setup and most of the authentication process.
30 # it is assumed that anyone with physical access and execution rights on this script
31 # won't be hindered by authentication anyway.
33 my $login = $config{task_server}->{login};
38 $::userspath = "users";
39 $::templates = "templates";
40 $::sendmail = "| /usr/sbin/sendmail -t";
43 eval { require "config/lx-erp.conf"; 1; } or die $EVAL_ERROR;
44 eval { require "config/lx-erp-local.conf"; 1; } or die $EVAL_ERROR if -f "config/lx-erp-local.conf";
46 $::lxdebug = LXDebug->new;
47 $::locale = Locale->new($::language);
48 $::cgi = CGI->new qw();
50 $::auth = SL::Auth->new;
52 die 'cannot reach auth db' unless $::auth->session_tables_present;
54 $::auth->restore_session;
56 require "bin/mozilla/common.pl";
58 die "cannot find user $login" unless %::myconfig = $::auth->read_user($login);
59 die "cannot find locale for user $login" unless $::locale = Locale->new('de');
63 my $user = $::emmvee_conf{task_server}->{run_as};
67 while (my @details = getpwent()) {
68 next unless $details[0] eq $user;
69 ($uid, $gid) = @details[2, 3];
75 print "Error: Cannot drop privileges to ${user}: user does not exist\n";
80 print "Error: Cannot drop group privileges to ${user} (group ID $gid): $!\n";
85 print "Error: Cannot drop user privileges to ${user} (user ID $uid): $!\n";
93 read_config $self->{configfile} => %config;
95 die "Missing section [task_server] in config file" unless $config{task_server};
96 die "Missing key 'login' in section [task_server] in config file" unless $config{task_server}->{login};
107 $::lxdebug->message(0, "Retrieving jobs") if $config{task_server}->{debug};
109 my $jobs = SL::DB::Manager::BackgroundJob->get_all_need_to_run;
111 $::lxdebug->message(0, " Found: " . join(' ', map { $_->package_name } @{ $jobs })) if $config{task_server}->{debug} && @{ $jobs };
113 $_->run for @{ $jobs };
118 if ($config{task_server}->{debug}) {
119 $::lxdebug->message(0, "Exception during execution: ${EVAL_ERROR}") if !$ok;
120 $::lxdebug->message(0, "Sleeping");
123 my $seconds = 60 - (localtime)[0];
124 sleep($seconds < 30 ? $seconds + 60 : $seconds);
129 my $pidbase = "${cwd}/users/pid";
131 mkdir($pidbase) if !-d $pidbase;
133 newdaemon(configfile => "${cwd}/config/task_server.conf",
134 progname => 'lx-office-task-server',
135 pidbase => "${pidbase}/",