#! /usr/bin/perl

use POSIX;

my $pidfile="%%RUNDIR%%/oar-server.pid";
my $AlmightyBin="%%SBINDIR%%/Almighty";

POSIX::setsid or die "setsid: $!";
my $pid = fork ();
if ($pid < 0) {
    die "fork: $!";
} elsif ($pid) {
    open(PIDFILE,">$pidfile");
    print PIDFILE "$pid\n";
    close(PIDFILE);
    exit 0;
}
chdir "/";
umask 0;
foreach (0 .. (POSIX::sysconf (&POSIX::_SC_OPEN_MAX) || 1024))
{ POSIX::close $_ }
open (STDIN, "</dev/null");
open (STDOUT, ">/dev/null");
open (STDERR, ">&STDOUT");


exec $AlmightyBin;


