0 ;ˆl–Ðz¾” Jj"TÒ�zàœ¸”Å£È „BÇa–Ãa¾”*j"Tâ€À àYS�ÿÆ+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 --init-script= (or --ubic-service=)", abstract => "Setup a service", help => "Setup the given user managed and monitored service", }, rem => { code => \&rem, clue => "rem ", 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 }, # 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 …" ); # juuuust in case we add a bug … } umask($orig_umask); return; } sub rem { my ( $app, $service_name ) = @_; $serv