Code

- wrong directory for a gosa-si-client.socket
[gosa.git] / gosa-si / gosa-si-server
index 5b21a7ced9acfa36a1af4bc7c0cd8c32385a0a70..8ee558119eca06ffad16ed54cd50ba35bcf9741e 100755 (executable)
@@ -17,7 +17,7 @@ gosa-si-server -Support infrastructure for GOsa
 
 =head1 SYNOPSIS
 
-gosa-si-server [-hvf] [-c config]
+gosa-si-server [-hvf] [-c config] [-x dump ]
 
 =head1 OPTIONS
 
@@ -55,6 +55,9 @@ B<-d> <int>
     256 : creation of packages_list_db
     512 : ARP debug information
 
+B<-x> <dump>
+     dump configuration to stdout
+     ( 1 = current, 2 = default )
 
 =head1 DESCRIPTION
 
@@ -142,7 +145,7 @@ my $repo_path;
 my %repo_dirs=();
 
 # Variables declared in config file are always set to 'our'
-our (%cfg_defaults, $log_file, $pid_file, $pid
+our (%cfg_defaults, $log_file, $pid_file, $pid,
     $server_ip, $server_port, $ClientPackages_key, $dns_lookup,
     $arp_activ, $gosa_unit_tag,
     $GosaPackages_key, $gosa_timeout,
@@ -312,7 +315,7 @@ our $check_periodic = {"months"=>'', "weeks"=>'', "days"=>'', "hours"=>'', "minu
     "messaging"             => [\$messaging_file_name, '/var/lib/gosa-si/messaging.db'],
     "foreign-clients"       => [\$foreign_clients_file_name, '/var/lib/gosa-si/foreign_clients.db'],
     "source-list"           => [\$sources_list, '/etc/apt/sources.list'],
-    "repo-path"             => [\$repo_path, '/srv/www'],
+    "repo-path"             => [\$repo_path, '/srv/www/debian'],
     "debian-arch"           => [\$arch, 'i386'],     
     "ldap-uri"              => [\$ldap_uri, ""],
     "ldap-base"             => [\$ldap_base, ""],
@@ -395,7 +398,7 @@ sub usage
                             'vvv': warning plus error logs                                             
                           'vvvvv': info plus warning logs
                         'vvvvvvv': debug plus info logs
-           -no-arp   : starts $prg without connection to arp module
+           -no-arp   : starts gosa-si-server without connection to arp module
            -d <int>  : if verbose level is higher than 7x 'v' specified parts can be debugged
                            1 : report incoming messages
                            2 : report unencrypted outgoing messages 
@@ -547,7 +550,7 @@ sub daemon_log {
 
                        # Build log message and write it to log file and commandline
                        chomp($msg);
-                       my $log_msg = "$month $monthday $hours:$minutes:$seconds$microSeconds $prg $msg\n";
+                       my $log_msg = "$month $monthday $hours:$minutes:$seconds$microSeconds $0 $msg\n";
                        flock(LOG_HANDLE, LOCK_EX);
                        seek(LOG_HANDLE, 0, 2);
                        print LOG_HANDLE $log_msg;
@@ -746,7 +749,7 @@ sub sig_int_handler {
                # to be removed rather crude !!
                #system("kill `ps -C gosa-si-server -o pid=`");
 
-               $pid->remove or warn "Could not remove $pidfile\n";
+               $pid->remove or warn "Could not remove $pid_file\n";
 
                exit(0);
 }
@@ -3626,8 +3629,8 @@ GetOptions( 'v|verbose+' => \$verbose,
             'h|help' => \&usage,
             'c|config=s' => \$config,
             'x|dump-config=i' => \$dump_config,
-            'f|foreground' => \$foreground)
-                                               'd=s' => \$debug_parts,
+            'f|foreground' => \$foreground,
+                                               'd=s' => \$debug_parts)
   or usage( '', 1 );
 
 # We may want to dump the default configuration
@@ -3641,8 +3644,6 @@ if( defined $dump_config ) {
 }
 
 #  read and set config parameters
-#&check_cmdline_param ;
-#&read_configfile($cfg_file, %cfg_defaults);
 &read_configfile($config, %cfg_defaults);
 #&check_pid;
 
@@ -3650,10 +3651,9 @@ if( defined $dump_config ) {
 $SIG{CHLD} = 'IGNORE';
 
 # Create the PID object
-# Ensure you put a name that won't clobber
-#   another program's PID file
-my $pid = File::Pid->new({
-   file  => $pidfile,
+# 
+$pid = File::Pid->new({
+   file  => $pid_file,
 });
 
 # Write the PID file
@@ -3674,7 +3674,7 @@ if( ! $foreground ) {
     umask 0;
 #} else {
 #    $pid = $$;
-#}
+}
 
 # Do something useful - put our PID into the pid_file
 #if( 0 != $pid ) {
@@ -3704,7 +3704,19 @@ open(my $FH, ">>", "$log_file");
 close($FH);
 chmod(0440, $log_file);
 chown($root_uid, $adm_gid, $log_file);
-chown($root_uid, $adm_gid, "/var/lib/gosa-si");
+
+# prepare directory for databases
+mkpath('/var/lib/gosa-si', 0, {owner=>'root', group=>'root'});
+
+# remove leftover files in tmp for packaged.db populate
+rmtree( '/tmp/packages_list_db',0,1);
+
+# remove list of sources from apt.sources.list
+unlink '/tmp/gosa_si_tmp_sources_list';
+
+# remove marker that the list creation is in progress
+unlink '/tmp/packages_list_creation_in_progress';
+
 
 daemon_log(" ", 1);
 daemon_log("$0 started!", 1);
@@ -3715,10 +3727,10 @@ daemon_log($server_status_hash->{$server_status}.": $server_revision", 1);
 {
     no strict "refs";
 
-    if ($db_module eq "DBmysql") {
-
-        daemon_log("0 INFO: importing database module '$db_module'", 1);
+               daemon_log("0 INFO: importing database module '$db_module'", 1);
 
+    if ($db_module eq "DBmysql") {
+    
         # connect to incoming_db
         $incoming_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
 
@@ -3751,66 +3763,69 @@ daemon_log($server_status_hash->{$server_status}.": $server_revision", 1);
 
     } elsif ($db_module eq "DBsqlite") {
 
-        daemon_log("0 INFO: importing database module '$db_module'", 1);
+        daemon_log("0 INFO: Removing SQLlite lock files", 1);
 
+                               # delete old DBsqlite lock files to be replace by rmtree !!
+                               system('rm -f /var/lib/gosa-si/*.si_lock*');
+                               
         # 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);
+                               #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);
+                               #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);
+                               #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);
+                               #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
+                               #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);
+                               #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);
+                               #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);
+                               #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);
+                               #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);
+                               #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);
+                               #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);
+                               #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);
+                               #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);
+                               #chmod(0640, $messaging_file_name);
+                               #chown($root_uid, $adm_gid, $messaging_file_name);
     }
 }
 
@@ -3901,9 +3916,9 @@ daemon_log("0 INFO: start socket for incoming xml messages at port '$server_port
 # create session for repeatedly checking the job queue for jobs
 POE::Session->create(
        inline_states => {
-               _start => \&session_start,
+                               _start => \&session_start,
         register_at_foreign_servers => \&register_at_foreign_servers,
-               control_server_registration => \&control_server_registration,
+                               control_server_registration => \&control_server_registration,
         sig_handler => \&sig_handler,
         next_task => \&next_task,
         task_result => \&handle_task_result,
@@ -3912,7 +3927,7 @@ POE::Session->create(
         watch_for_new_messages => \&watch_for_new_messages,
         watch_for_delivery_messages => \&watch_for_delivery_messages,
         watch_for_done_messages => \&watch_for_done_messages,
-               watch_for_new_jobs => \&watch_for_new_jobs,
+                               watch_for_new_jobs => \&watch_for_new_jobs,
         watch_for_modified_jobs => \&watch_for_modified_jobs,
         watch_for_done_jobs => \&watch_for_done_jobs,
         watch_for_opsi_jobs => \&watch_for_opsi_jobs,
@@ -3920,7 +3935,7 @@ POE::Session->create(
         create_packages_list_db => \&run_create_packages_list_db,
         create_fai_server_db => \&run_create_fai_server_db,
         create_fai_release_db => \&run_create_fai_release_db,
-               recreate_packages_db => \&run_recreate_packages_db,
+                               recreate_packages_db => \&run_recreate_packages_db,
         session_run_result => \&session_run_result,
         session_run_debug => \&session_run_debug,
         session_run_done => \&session_run_done,