diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 88e13681e45cdca30dd594b9091c1d8596065036..9d92dc9971e4d9fe7c5f66a4cce57c8c4eca45d4 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
our $client_fai_log_dir = "/var/log/fai";
# queue which stores taskes until one of the $max_children children are ready to process the task
-#my @tasks = qw();
my @msgs_to_decrypt = qw();
my $max_children = 2;
}
}
-
-#=== FUNCTION ================================================================
-# NAME: check_cmdline_param
-# PARAMETERS: nothing
-# RETURNS: nothing
-# DESCRIPTION: validates commandline parameter
-#===============================================================================
-sub check_cmdline_param () {
- my $err_counter = 0;
-
- # Check configuration file
- if(not defined($cfg_file)) {
- $cfg_file = "/etc/gosa-si/server.conf";
- if(! -r $cfg_file) {
- print STDERR "Please specify a config file.\n";
- $err_counter++;
- }
- }
-
- # Prepare identification which gosa-si parts should be debugged and which not
- if (defined $debug_parts)
- {
- if ($debug_parts =~ /^\d+$/)
- {
- $debug_parts_bitstring = unpack("B32", pack("N", $debug_parts));
- }
- else
- {
- print STDERR "Value '$debug_parts' invalid for option d (number expected)\n";
- $err_counter++;
- }
- }
-
- # Exit if an error occour
- if( $err_counter > 0 ) { &usage( "", 1 ); }
-}
-
-
-#=== FUNCTION ================================================================
-# NAME: check_pid
-# PARAMETERS: nothing
-# RETURNS: nothing
-# DESCRIPTION: handels pid processing
-#===============================================================================
-sub check_pid {
- $pid = -1;
- # Check, if we are already running
- if( open( my $LOCK_FILE, "<", "$pid_file" ) ) {
- $pid = <$LOCK_FILE>;
- if( defined $pid ) {
- chomp( $pid );
- if( -f "/proc/$pid/stat" ) {
- my($stat) = `cat /proc/$pid/stat` =~ m/$pid \((.+)\).*/;
- if( $stat ) {
- print STDERR "\nERROR: Already running!\n";
- close( $LOCK_FILE );
- exit -1;
- }
- }
- }
- close( $LOCK_FILE );
- unlink( $pid_file );
- }
-
- # create a syslog msg if it is not to possible to open PID file
- if (not sysopen(my $LOCK_FILE, $pid_file, O_WRONLY|O_CREAT|O_EXCL, 0644)) {
- my($msg) = "Couldn't obtain lockfile '$pid_file' ";
- if (open(my $LOCK_FILE, '<', $pid_file)
- && ($pid = <$LOCK_FILE>))
- {
- chomp($pid);
- $msg .= "(PID $pid)\n";
- } else {
- $msg .= "(unable to read PID)\n";
- }
- if( ! ($foreground) ) {
- openlog( $0, "cons,pid", "daemon" );
- syslog( "warning", $msg );
- closelog();
- }
- else {
- print( STDERR " $msg " );
- }
- exit( -1 );
- }
-}
-
#=== FUNCTION ================================================================
# NAME: import_modules
# PARAMETERS: module_path - string - abs. path to the directory the modules
# DESCRIPTION: handle tasks to be done before signal becomes active
#===============================================================================
sub sig_int_handler {
- my ($signal) = @_;
+ my ($signal) = @_;
# if (defined($ldap_handle)) {
# $ldap_handle->disconnect;
# }
- # TODO alle verbliebenden ldap verbindungen aus allen heaps beenden
+# TODO all ldap connections shoudl be closed
- daemon_log("shutting down gosa-si-server", 1);
-
- $global_kernel->yield(TCP_SERVER => 'shutdown');
+ daemon_log("shutting down gosa-si-server", 1);
- # to be removed rather crude !!
- #system("kill `ps -C gosa-si-server -o pid=`");
+ # asking the poe kernel to shutdown the server
+ $global_kernel->yield(TCP_SERVER => 'shutdown');
- $pid->remove or warn "Could not remove $pid_file\n";
+ # removing the pidfile
+ $pid->remove or warn "Could not remove $pid_file\n";
- exit(0);
+ exit(0);
}
$SIG{INT} = \&sig_int_handler;
}
sub session_start {
- my ($kernel) = $_[KERNEL];
- $global_kernel = $kernel;
- $kernel->yield('register_at_foreign_servers');
+ my ($kernel) = $_[KERNEL];
+ $global_kernel = $kernel;
+ $kernel->yield('register_at_foreign_servers');
$kernel->yield('create_fai_server_db', $fai_server_tn );
$kernel->yield('create_fai_release_db', $fai_release_tn );
$kernel->sig(USR1 => "sig_handler");
$kernel->sig(USR2 => "recreate_packages_db");
$kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay);
$kernel->delay_set('watch_for_done_jobs', $job_queue_loop_delay);
- $kernel->delay_set('watch_for_modified_jobs', $modified_jobs_loop_delay);
+ $kernel->delay_set('watch_for_modified_jobs', $modified_jobs_loop_delay);
$kernel->delay_set('watch_for_new_messages', $messaging_db_loop_delay);
- $kernel->delay_set('watch_for_delivery_messages', $messaging_db_loop_delay);
+ $kernel->delay_set('watch_for_delivery_messages', $messaging_db_loop_delay);
$kernel->delay_set('watch_for_done_messages', $messaging_db_loop_delay);
- $kernel->delay_set('watch_for_old_known_clients', $job_queue_loop_delay);
+ $kernel->delay_set('watch_for_old_known_clients', $job_queue_loop_delay);
- # Start opsi check
- if ($opsi_enabled eq "true") {
- $kernel->delay_set('watch_for_opsi_jobs', $job_queue_opsi_delay);
- }
+ # Start opsi check
+ if ($opsi_enabled eq "true") {
+ $kernel->delay_set('watch_for_opsi_jobs', $job_queue_opsi_delay);
+ }
}
sub start_daemon {
+ #to prevent zombie child
+ $SIG{CHLD} = 'IGNORE';
+
if( ! $foreground ) {
chdir '/' or die "Can't chdir to /: $!";
umask 0;
open STDIN, '+>/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, '+>&STDIN' or die "Can't write to /dev/null: $!";
open STDERR, '+>&STDIN' or die "Can't write to /dev/null: $!";
- defined(my $child_pid = fork) or die "Can't fork: $!";
- exit if $child_pid;
+ defined($pid = fork) or die "Can't fork: $!";
+ exit if $pid;
setsid or die "Can't start a new session: $!";
}
return;
# read and set config parameters
&read_configfile($config, %cfg_defaults);
+# daemonize the program
+&start_daemon($pid, $foreground);
+
# create pid file
&create_pid($pid, $pid_file);
-# daemonize the program
-&start_daemon($foreground);
-
# Determine root uid and adm gid, used for creating log files
&get_perms_admin($root_uid, $adm_gid);
&open_log($root_uid, $adm_gid, $log_file);
# prepare directory for databases
-mkpath('/var/lib/gosa-si', 0, {owner=>'root', group=>'root'});
+mkpath('/var/lib/gosa-si', 0, {owner=>'root', group=>'root', mode=> '0755'});
# remove leftover files in tmp for packaged.db populate
rmtree( '/tmp/packages_list_db',0,1);
# connect to incoming_db
unlink($incoming_file_name);
$incoming_db = ("GOsaSI::".$db_module)->new($incoming_file_name);
- #chmod(0640, $incoming_file_name);
- #chown($root_uid, $adm_gid, $incoming_file_name);
-
+
# connect to gosa-si job queue
$job_db = ("GOsaSI::".$db_module)->new($job_queue_file_name);
- #chmod(0640, $job_queue_file_name);
- #chown($root_uid, $adm_gid, $job_queue_file_name);
# connect to known_clients_db
- #unlink($known_clients_file_name);
$known_clients_db = ("GOsaSI::".$db_module)->new($known_clients_file_name);
- #chmod(0640, $known_clients_file_name);
- #chown($root_uid, $adm_gid, $known_clients_file_name);
# connect to foreign_clients_db
- #unlink($foreign_clients_file_name);
$foreign_clients_db = ("GOsaSI::".$db_module)->new($foreign_clients_file_name);
- #chmod(0640, $foreign_clients_file_name);
- #chown($root_uid, $adm_gid, $foreign_clients_file_name);
# connect to known_server_db
- #unlink($known_server_file_name); # do not delete, gosa-si-server should be forced to check config file and dns at each start
$known_server_db = ("GOsaSI::".$db_module)->new($known_server_file_name);
- #chmod(0640, $known_server_file_name);
- #chown($root_uid, $adm_gid, $known_server_file_name);
# connect to login_usr_db
- #unlink($login_users_file_name);
$login_users_db = ("GOsaSI::".$db_module)->new($login_users_file_name);
- #chmod(0640, $login_users_file_name);
- #chown($root_uid, $adm_gid, $login_users_file_name);
# connect to fai_server_db
- #unlink($fai_server_file_name);
$fai_server_db = ("GOsaSI::".$db_module)->new($fai_server_file_name);
- #chmod(0640, $fai_server_file_name);
- #chown($root_uid, $adm_gid, $fai_server_file_name);
# connect to fai_release_db
- #unlink($fai_release_file_name);
$fai_release_db = ("GOsaSI::".$db_module)->new($fai_release_file_name);
- #chmod(0640, $fai_release_file_name);
- #chown($root_uid, $adm_gid, $fai_release_file_name);
# connect to packages_list_db
- #unlink($packages_list_under_construction);
$packages_list_db = ("GOsaSI::".$db_module)->new($packages_list_file_name);
- #chmod(0640, $packages_list_file_name);
- #chown($root_uid, $adm_gid, $packages_list_file_name);
# connect to messaging_db
- #unlink($messaging_file_name);
$messaging_db = ("GOsaSI::".$db_module)->new($messaging_file_name);
- #chmod(0640, $messaging_file_name);
- #chown($root_uid, $adm_gid, $messaging_file_name);
}
}