#!/usr/bin/perl -w # Zymonic Business Process and Information Management System # Copyright Zednax Limited 2008 - # For Authors and Changelog see the subversion history BEGIN { use Zymonic::Utils qw(death_handler clean); use vars qw(%modules); %modules = (); use sigtrap 'handler' => \&global_handler, 'normal-signals', 'handler' => \&global_handler, 'error-signals'; $main::SIG{__DIE__} = \&global_handler; sub global_handler { # cleanup all modules before anything map { $_->cleanup() } values %modules; exit(0) if $_[0] eq 'TERM'; death_handler($@); } no warnings; $SIG{CHLD} = 'IGNORE'; $SIG{CHILD} = 'IGNORE'; # Second instance for Solaris compatibility use warnings; } use Zymonic; use Zymonic::DaemonModule; use Config::Simple; use Sys::Hostname; # autoflush all logs $| = 1; # load up the config file my $config_file = '/etc/zymonic/daemon.conf'; my %config; Config::Simple->import_from( $config_file, \%config ) or Zymonic::Exception::FileIO::Read->throw( filename => $config_file, error => Config::Simple->error() ); # remove the default namespace %config = map { my $key = $_; $key =~ s/^default\.//g; $key => $config{$_} } keys %config; # debugfile my $fh; my $debug_file = clean( $ARGV[1], '\/_' ) || ''; if ($debug_file) { $Zymonic::Utils::DEBUG_AS_SQLITE = 0; open( $fh, ">", $debug_file ) || die "Couldn't open debug file"; $| = 1; $Zymonic::Utils::debugfile = $fh; } else { $Zymonic::Utils::debugs_written = 1; } # load up each module my @modules = (); if ( ref( $config{modules} ) ) { @modules = @{ $config{modules} }; } else { @modules = ( $config{modules} ); } foreach my $module (@modules) { $modules{$module} = Zymonic::DaemonModule->new( module => $module, daemon_config => \%config, host => hostname, nofork => $ARGV[0] || '', ); } print "Zymonic Daemon started.\n"; # TODO: loop and accept incoming connections and pass them on to required module # The idea is that an incoming connection would have a module and args, # you would then lookup module and do connection_start, handle_connection($args), connection_end # not needed yet, hence it's just a stub which does nothing sleep; # should never reach here, output a message just in case print "Zymonic Daemon stopped.\n";