#!/usr/local/cpanel/3rdparty/bin/perl

package scripts::cpanel_dovecot_solr_isonline;

# cpanel - scripts/cpanel_dovecot_solr_isonline      Copyright 2017 cPanel, Inc.
#                                                           All Rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

=encoding utf-8

=head1 NAME

cpanel_dovecot_solr_isonline

=head1 SYNOPSIS

    cpanel_dovecot_solr_isonline

=head1 DESCRIPTION

This script prints "running" if solr is answering on port 8984.

=cut

use strict;
use warnings;

use IO::Socket::INET ();

use constant DEFAULT_SOLR_PORT => 8984;

our $VERSION = '1.0';

exit __PACKAGE__->run(@ARGV) unless caller();

sub run {
    my ( $class, @args ) = @_;

    my $SOLR_PORT = $ENV{'SOLR_PORT'} || DEFAULT_SOLR_PORT;

    local $@;
    my $obj = IO::Socket::INET->new( 'PeerAddr' => "127.0.0.1:$SOLR_PORT", 'Timeout' => 3 );

    if ( $obj && !$@ ) {
        print "running\n";
        return 0;
    }

    #failure
    return 1;
}

1;
