aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_status/src/main/perl/jdisc_status_conf.pl
blob: 3e02f42c46de6363a770d46118d4fd56dd4c5cb2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/local/bin/perl -w
# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

# BEGIN perl environment bootstrap section
# Do not edit between here and END as this section should stay identical in all scripts

use File::Basename;
use File::Path;

sub findpath {
    my $myfullname = ${0};
    my($myname, $mypath) = fileparse($myfullname);

    return $mypath if ( $mypath && -d $mypath );
    $mypath=`pwd`;

    my $pwdfullname = $mypath . "/" . $myname;
    return $mypath if ( -f $pwdfullname );
    return 0;
}

# Returns the argument path if it seems to point to VESPA_HOME, 0 otherwise
sub is_vespa_home {
    my($VESPA_HOME) = shift;
    my $COMMON_ENV="libexec/vespa/common-env.sh";
    if ( $VESPA_HOME && -d $VESPA_HOME ) {
        my $common_env = $VESPA_HOME . "/" . $COMMON_ENV;
        return $VESPA_HOME if -f $common_env;
    }
    return 0;
}

# Returns the home of Vespa, or dies if it cannot
sub findhome {
    # Try the VESPA_HOME env variable
    return $ENV{'VESPA_HOME'} if is_vespa_home($ENV{'VESPA_HOME'});
    if ( $ENV{'VESPA_HOME'} ) { # was set, but not correctly
        die "FATAL: bad VESPA_HOME value '" . $ENV{'VESPA_HOME'} . "'\n";
    }

    # Try the ROOT env variable
    $ROOT = $ENV{'ROOT'};
    return $ROOT if is_vespa_home($ROOT);

    # Try the script location or current dir
    my $mypath = findpath();
    if ($mypath) {
        while ( $mypath =~ s|/[^/]*$|| ) {
            return $mypath if is_vespa_home($mypath);
        }
    }
    die "FATAL: Missing VESPA_HOME environment variable\n";
}

BEGIN {
    my $tmp = findhome();
    if ( $tmp !~ m{[/]$} ) { $tmp .= "/"; }
    $ENV{'VESPA_HOME'} = $tmp;
}
my $VESPA_HOME = $ENV{'VESPA_HOME'};

# END perl environment bootstrap section

use lib $ENV{'VESPA_HOME'} . '/lib/perl5/site_perl';
use Yahoo::Vespa::Defaults;
readConfFile();

use strict;
use Data::Dumper;

print <<EOF;
###########################################################################
# DO NOT EDIT THIS FILE, IT WILL BE OVERWRITTEN.
###########################################################################

EOF

my $file = '$VESPA_HOME/libexec/jdisc/status.html';

if (defined $ENV{'jdisc_status__status_file'}) {
  $file = $ENV{'jdisc_status__status_file'};
}

print "desc = jdisc status files\n";
print "file = $file\n";
print "email = " . $ENV{'jdisc_status__email'} . "\n" if defined $ENV{'jdisc_status__email'};
print "prompt = " . $ENV{'jdisc_status__msg'} . "\n" if defined $ENV{'jdisc_status__msg'};
print "ymon = 1\n" if defined $ENV{'jdisc_status__manage_ymon_notifications'} and $ENV{'jdisc_status__manage_ymon_notifications'} == 1;
print "data_extended = 1\n" if defined $ENV{'jdisc_status__data_extended'};

if (defined($ENV{'jdisc_status__boot'}) and
    ($ENV{'jdisc_status__boot'} eq 'autostart' || $ENV{'jdisc_status__boot'} eq 'autostop')) {
    print "boot = " . $ENV{'jdisc_status__boot'} . "\n";
}