#!/usr/bin/env perl
# vim:ts=4:sw=4:expandtab

use strict;
use warnings;
use utf8;
use v5.10;
use lib qw(lib);
use Kanla;
use AnyEvent;
use Getopt::Long;
use Pod::Usage;
use POSIX qw(setsid);

binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';

# Disable buffering,
# otherwise stdout and stderr
# are interleaved
# e.g. in journald.
$| = 1;

my $configfile;
GetOptions(
    'configfile=s' => \$configfile,
    'help'         => sub {
        pod2usage({
                -verbose => 1,
                -exitval => 0,
        });
    },
    'version' => sub {
        say
"kanla $Kanla::VERSION © 2012-2014 Michael Stapelberg and contributors";
        exit 0;
    },
);

# Open a new session
# so that init scripts
# can kill kanla plus all plugins
# by using kill -$(pidof kanla)
setsid();

Kanla::run(configfile => $configfile);

# Run forever.
AnyEvent->condvar->recv;

=head1 NAME

kanla - small-scale alerting daemon

=head1 SYNOPSIS

    kanla [--configfile=path]

=head1 DESCRIPTION

kanla is a daemon which peridiocally checks
whether your website, mail server, etc.
are still up and running.

In case a health check fails,
kanla will notify you
via jabber (XMPP).

Focus of kanla lies on
being light-weight,
being simple,
using a sane configuration file,
being well-documented.

=head1 OPTIONS

=over

=item B<--configfile=path>

Use path instead of /etc/kanla/default.cfg as configuration file.

=back

=head1 DOCUMENTATION

kanla's documentation can be found at
http://kanla.zekjur.net/docs/

We have decided to use asciidoc for kanla,
and to not maintain both POD and asciidoc,
the POD documentation is intentionally sparse.

=head1 VERSION

Version 1.5

=head1 AUTHOR

Michael Stapelberg, C<< <michael at stapelberg.de> >>

=head1 LICENSE AND COPYRIGHT

Copyright 2012-2014 Michael Stapelberg.

This program is free software; you can redistribute it and/or modify it
under the terms of the BSD license.

=cut
