Edit File: find_outdated_services
#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - scripts/find_outdated_services 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 package scripts::find_outdated_services; =encoding utf-8 =head1 NAME F<scripts/find_outdated_services> =head1 USAGE find_outdated_services [ --always-restart | --never-restart ] find_outdated_services --help =head1 DESCRIPTION This command examines your system and identifies any services that are “outdated”—i.e., that depend on libraries that are no longer present on the system. This can often happen when such libraries receive updates, e.g., from C<yum>. Normal behavior is to ask you whether you’d like to restart the outdated service(s); however, you can specify the C<--always-restart> or C<--never-restart> flags to bypass this prompt and either restart or not, respectively. =cut use strict; use warnings; use Try::Tiny; use IO::Prompt (); use Cpanel::Alarm (); use Cpanel::ProcessCheck::Outdated (); use Cpanel::Services (); use parent qw( Cpanel::HelpfulScript ); use constant _OPTIONS => ( 'always-restart', 'never-restart', ); exit __PACKAGE__->new(@ARGV)->run() if !caller; sub run { my ($self) = @_; my $alarm = Cpanel::Alarm->new( 90 * 3600 ); #90 minutes $self->say_maketext('Looking for outdated services …'); my $err; my @services = try { grep( !m/^httpd\.service$/, _get_outdated_services() ); # yum hooks already restart apache when needed } catch { $err = $_; if ( !try { $err->isa('Cpanel::Exception::Unsupported') } ) { local $@ = $err; die; } print STDERR $err; }; return 1 if $err; if (@services) { s<\.service\z><> for @services; $self->say(q<>); $self->say_maketext( 'The system found [quant,_1,outdated service,outdated services]:', 0 + @services ); $self->say("\t$_") for @services; my $proceed_yn = $self->getopt('always-restart'); $proceed_yn //= $self->getopt('never-restart') ? 0 : undef; my $yes = $self->locale()->maketext('Yes'); $proceed_yn //= IO::Prompt::prompt( '-one_char', '-yes_no', "\n" . $self->locale()->maketext( 'Would you like to restart [numerate,_1,this service,these services]?', 0 + @services ) . ' [y/n]: ', ); if ($proceed_yn) { for my $svc (@services) { $self->say(q<>); $self->say_maketext( 'Restarting “[_1]” …', $svc ); #Since we don’t report anything other than just #success or failure, and we want STDOUT and STDERR #to pass through, the system() built-in is fine. my $output = Cpanel::Services::restartservice($svc); my $msg; if ( $output =~ m/ has failed/ ) { $msg = $self->locale()->maketext( 'The system failed to restart “[_1]”.', $svc ); } else { $msg = $self->locale()->maketext( 'The system has restarted “[_1]”.', $svc ); } $self->say( $self->bold($msg) ); } } } else { $self->say_maketext('The system did not find any outdated services.'); } return 0; } #---------------------------------------------------------------------- #overridden in tests BEGIN { *_get_outdated_services = *Cpanel::ProcessCheck::Outdated::outdated_services; } 1;