Ubic

 view release on metacpan or  search on metacpan

lib/Ubic/Admin/Setup.pm  view on Meta::CPAN

            $local = 1 unless $ok; # root can install locally
        }
        else {
            my $ok = prompt_bool("You are not root, install locally?", 1);
            return unless $ok; # non-root user can't install into system
            $local = 1;
        }
    }

    my $local_dir;
    if ($local) {
        $local_dir = $ENV{HOME};
        unless (defined $local_dir) {
            die "Can't find your home!";
        }
        unless (-d $local_dir) {
            die "Can't find your home dir '$local_dir'!";
        }
    }

    print_tty "\nService dir is a directory with descriptions of your services.\n";
    my $default_service_dir = (
        defined($local_dir)
        ? "$local_dir/ubic/service"
        : $defaults{service_dir}
    );
    $default_service_dir = $opt_service_dir if defined $opt_service_dir;
    my $service_dir = prompt_str("Service dir?", $default_service_dir);

    print_tty "\nData dir is where ubic stores all of its data: locks,\n";
    print_tty "status files, tmp files.\n";
    my $default_data_dir = (
        defined($local_dir)
        ? "$local_dir/ubic/data"
        : $defaults{data_dir}
    );
    $default_data_dir = $opt_data_dir if defined $opt_data_dir;
    my $data_dir = prompt_str("Data dir?", $default_data_dir);

    print_tty "\nLog dir is where ubic.watchdog will write its logs.\n";
    print_tty "(Your own services are free to write logs wherever they want.)\n";
    my $default_log_dir = (
        defined($local_dir)
        ? "$local_dir/ubic/log"
        : $defaults{log_dir}
    );
    $default_log_dir = $opt_log_dir if defined $opt_log_dir;
    my $log_dir = prompt_str("Log dir?", $default_log_dir);

    # TODO - sanity checks?

    my $default_user;
    if ($is_root) {
        print_tty "\nUbic services can be started from any user.\n";
        print_tty "Some services don't specify the user from which they must be started.\n";
        print_tty "Default user will be used in this case.\n";
        $default_user = prompt_str("Default user?", $opt_default_user);
    }
    else {
        print_tty "\n";
        $default_user = getpwuid($>);
        unless (defined $default_user) {
            die "Can't get login (uid '$>')";
        }
        print_tty "You're using local installation, so default service user will be set to '$default_user'.\n";
    }

    my $enable_1777;
    if ($is_root) {
        print_tty "\nSystem-wide installations usually need to store service-related data\n";
        print_tty "into data dir for different users. For non-root services to work\n";
        print_tty "1777 grants for some data dir subdirectories is required.\n";
        print_tty "(1777 grants means that everyone is able to write to the dir,\n";
        print_tty "but only file owners are able to modify and remove their files.)\n";
        print_tty "There are no known security issues with this approach, but you have\n";
        print_tty "to decide for yourself if that's ok for you.\n";

        $enable_1777 = prompt_bool("Enable 1777 grants for data dir?", $opt_sticky_777);
    }

    my $install_services;
    {
        print_tty "There are three standard services in ubic service tree:\n";
        print_tty " - ubic.watchdog (universal watchdog)\n";
        print_tty " - ubic.ping (http service status reporter)\n";
        print_tty " - ubic.update (helper process which updates service portmap, used by ubic.ping service)\n";
        print_tty "If you'll choose to install them, ubic.watchdog will be started automatically\n";
        print_tty "and two other services will be initially disabled.\n";
        $install_services = prompt_bool("Do you want to install standard services?", $opt_install_services);
    }

    my $enable_crontab;
    {
        print_tty "\n'ubic.watchdog' is a service which checks all services and restarts them if\n";
        print_tty "there are any problems with their statuses.\n";
        print_tty "It is very simple and robust, but since it's important that watchdog never\n";
        print_tty "goes down, we recommended to install the cron job which checks watchdog itself.\n";
        print_tty "Also, this cron job will bring watchdog and all other services online on host reboots.\n";
        $enable_crontab = prompt_bool("Install watchdog's watchdog as a cron job?", $opt_crontab);
    }

    my $crontab_env_fix = '';
    my $crontab_wrap_bash;
    my $ubic_watchdog_full_name = which('ubic-watchdog') or die "ubic-watchdog script not found in your current PATH";
    {
        my @path = split /:/, $ENV{PATH};
        my @perls = grep { -x $_ } map { "$_/perl" } @path;
        if ($perls[0] =~ /perlbrew/) {
            print_tty "\nYou're using perlbrew.\n";

            my $HOME = $ENV{ORIGINAL_HOME} || $ENV{HOME}; # ORIGINAL_HOME is set in ubic tests
            unless ($HOME) {
                die "HOME env variable not defined";
            }
            my $perlbrew_config = File::Spec->catfile($ENV{PERLBREW_ROOT} || "$HOME/perl5/perlbrew", "etc/bashrc");
            if (not -e $perlbrew_config) {
                die "Can't find perlbrew config (assumed $perlbrew_config)";
            }
            print_tty "I'll source your perlbrew config in ubic crontab entry to start the watchdog in the correct environment.\n";
            $crontab_env_fix .= "source $perlbrew_config && ";
            $crontab_wrap_bash = 1;



( run in 3.331 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )