Changeset 11239

Show
Ignore:
Timestamp:
08/19/08 15:38:38 (5 months ago)
Author:
/C=ES/O=Warp Networks S.L./CN=ejhernandez@…
Message:

Added upstart conf file and added foreground option to be run runnerd under upstart supervision refs #1103

Location:
branches/remote-services/ebox
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • branches/remote-services/ebox/src/libexec/ebox-runnerd

    r11237 r11239  
    44use EBox::Config; 
    55use EBox::Exceptions::External; 
     6use Getopt::Long; 
    67use Linux::Inotify2; 
    78use POSIX qw(SIG_IGN SIGHUP); 
     
    1617#     Stevens chapter 13 coding rules 
    1718# 
     19# Parameters: 
     20# 
     21#     foreground - Boolean indicating if the daemon must be launched 
     22#     in foreground *(Optional)* Default value: false 
     23# 
     24# 
    1825sub _daemonise 
    1926{ 
     27    my ($foreground) = @_; 
     28 
    2029    # Clear the file creation mask 
    2130    umask(0); 
     31 
     32    unless ( $foreground ) { 
    2233    # Become a session leader to lose controlling TTY 
    23     my $pid = fork(); 
    24     if ( $pid < 0 ) { 
    25         throw EBox::Exceptions::External( "Cannot fork: $!"); 
    26     } elsif ( $pid != 0 ) { 
    27         # Parent must throw EBox::Exceptions::External( 
    28         exit(0); 
     34        my $pid = fork(); 
     35        if ( $pid < 0 ) { 
     36            throw EBox::Exceptions::External( "Cannot fork: $!"); 
     37        } elsif ( $pid != 0 ) { 
     38            # Parent must throw EBox::Exceptions::External( 
     39            exit(0); 
     40        } 
     41        POSIX::setsid(); 
    2942    } 
    30     POSIX::setsid(); 
    3143 
    3244    # Ensure future opens won't allocate controlling TTYs 
    3345    POSIX::sigaction(POSIX::SIGHUP, POSIX::SigAction->new( POSIX::SIG_IGN )) 
    3446        or throw EBox::Exceptions::External( "Cannot ignore SIGHUP: $!"); 
    35     my $pid = fork(); 
    36     if ( $pid < 0 ) { 
    37         throw EBox::Exceptions::External( "Cannot fork: $!"); 
    38     } elsif ( $pid != 0 ) { 
    39         # Parent must die 
    40         exit(0); 
     47    unless ( $foreground ) { 
     48        my $pid = fork(); 
     49        if ( $pid < 0 ) { 
     50            throw EBox::Exceptions::External( "Cannot fork: $!"); 
     51        } elsif ( $pid != 0 ) { 
     52            # Parent must die 
     53            exit(0); 
     54        } 
    4155    } 
    4256 
     
    106120 
    107121# MAIN 
     122 
     123# Get arguments 
     124my ($foreground) = (0); 
     125my $result = GetOptions( 'foreground' => \$foreground ); 
     126 
    108127EBox::init(); 
    109 _daemonise(); 
     128_daemonise($foreground); 
    110129 
    111130my $incomingSub = sub {