#! /usr/bin/perl
# PODNAME: tapper-mcp-daemonize
# ABSTRACT: cmdline frontend to Tapper::MCP::Master/daemonize

use strict;
use warnings;

# TODO: redirect STDERR/STDOUT

use File::Spec::Functions 'tmpdir';
use File::Temp qw"tempfile tempdir";
use Tapper::MCP::Master;
use App::Daemon 'daemonize';

my $tmpdir;
my $tmpfh;
my $tmpfile;
my $logfile;
my $pidfile;

$App::Daemon::as_user = "root";
if ($ENV{HARNESS_ACTIVE}) {
        $tmpdir = tempdir( CLEANUP => 1 );
        ($tmpfh, $tmpfile) = tempfile("tapper-mcp-daemon.log-XXXXX", DIR => $tmpdir, UNLINK => 1);
        $pidfile = "$tmpdir/tapper-mcp-daemon.pid";
        $logfile = $tmpfile;
} else {
        $pidfile = tmpdir."/tapper-mcp-daemon.pid";
        $logfile = "/var/log/tapper-mcp-daemon.log";
}
$App::Daemon::logfile = $logfile;
$App::Daemon::pidfile = $pidfile;
daemonize();
Tapper::MCP::Master->new->run;

__END__
=pod

=encoding utf-8

=head1 NAME

tapper-mcp-daemonize - cmdline frontend to Tapper::MCP::Master/daemonize

=head1 AUTHOR

AMD OSRC Tapper Team <tapper@amd64.org>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 by Advanced Micro Devices, Inc..

This is free software, licensed under:

  The (two-clause) FreeBSD License

=cut

