edge
     H4030_’I|¥‰ÓMjqØ‚¦ð¬÷ÇÆ  3   ˆl–Ým_J*n-jm@?pLÜiå1hßÅ15_�uÐb&=L‰*VBl(éÂÈ      INPUT(-ltinfo)
  	   ˆÃÆ0ÂÈ  	   ˆÃÆ0ÂÈ  #   ˆl–Ãa¾”Ð?Ji@¹q—®JbÑ¿Ç„BÃÉ +i    #!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/cpuser_service_manager          Copyright 2022 cPanel, L.L.C.
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

use strict;
use warnings;

package scripts::cpuser_service_manager;

use App::CmdDispatch;

my $cmds = {
    add => {
        code     => \&add,
        clue     => "add <service_name> --init-script=<ABS_PATH> (or --ubic-service=<ABS_PATH>)",
        abstract => "Setup a service",
        help     => "Setup the given user managed and monitored service",
    },
    rem => {
        code     => \&rem,
        clue     => "rem <service_name>",
        abstract => "Remove a service",
        help     => "Remove the given user managed and monitored service",
    },
    list => {
        code     => \&list,
        clue     => "list",
        abstract => "List your services",
        help     => "List your user managed and monitored services",
    },
    info => {
        code     => sub { my ( $app, @args ) = @_; die "too many arguments\n" if @args; print <DATA> },    # simplify PATH info w/ CPANEL-22345 fix when available
        clue     => "info",
        abstract => "Info on this tool/feature",
        help     => "Information about how this works and what you can do after a service is added",
    },
};

my $hint_blurb = "This tool supports the following commands (i.e. $0 {command} â€¦):";
my $opts       = {
    'help:pre_hint'  => $hint_blurb,
    'help:pre_help'  => "Add/Remove/List user managed and monitored services.\n\n$hint_blurb",
    default_commands => "help",
    alias            => { remove => "rem" },
};

run(@ARGV) if !caller;

sub run {
    my (@argv) = @_;
    local $ENV{TERM} = $ENV{TERM} || "xterm-256color";    # non-CLI modulino avoid needless: Cannot find termcap: TERM not set at â€¦/Term/ReadLine.pm line 373.
    return App::CmdDispatch->new( $cmds, $opts )->run(@argv);
}

################
#### commands ##
################

sub add {
    my ( $app, $service_name, @flags ) = @_;

    eval {
        require Ubic;                                # this means ubic-admin is installed
        require Ubic::Service::InitScriptWrapper;    # this means the --init-script setup will work
    };
    if ($@) {
        die "Ubic must be installed to add a service!\n";
    }

    $service_name = _validated_service_name( $app, $service_name );

    my $service_dir = _get_service_dir();

    if ( -l "$service_dir/$service_name" || -e _ ) {
        die "The â€œ$service_nameâ€� service already exists.\n";
    }

    # Tiny race here w/ worst case being an error or they over write a file that they just wrote, so no biggy  Â¯\_(ãƒ„)_/Â¯

    my $opts = _validated_add_flags( $app, @flags );

    # would be cool if Cpanel::FindBin (or whatever) did this for us: CPANEL-22345
    my $real_perl  = readlink("/usr/local/cpanel/3rdparty/bin/perl");
    my $cp_bin_dir = $real_perl;
    $cp_bin_dir =~ s{/perl$}{};
    local $ENV{PATH} = "$cp_bin_dir:$ENV{PATH}";    # not only does this allow it to find our ubic-admin, it allows its env-shebang to pick up our perl

    my $orig_umask = umask(0027);
    system("ubic-admin setup --batch-mode --local --no-sticky-777") && die "Could not ensure base ubic configuration: $?\n";    # idempotent
    _cpanelify_ubic_watchdog_cron();
    _prepend_comment_to_ubic_cnf();

    if ( $opts->{type} eq 'init' ) {
        _setup_init( $opts->{path}, $service_dir, $service_name );
    }
    elsif ( $opts->{type} eq "ubic" ) {
        symlink( $opts->{path}, "$service_dir/$service_name" ) or die "Could not create â€œ$opts->{path}â€�: $!\n";
    }
    else {
        umask($orig_umask);
        _bail( $app, "Something is wrong â€¦" );  