Edit File: rpmup
#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - scripts/rpmup Copyright 2015 cPanel, Inc. # All rights Reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited # # This script effectively does a yum -y update # Only update methods for RHEL 4-6 are supported package scripts::rpmup; use strict; use warnings; use Cpanel::Imports; use Getopt::Param (); use Cpanel::Update::Config (); use Cpanel::SysPkgs (); use Cpanel::PackMan (); use Cpanel::ProgLang (); use Cpanel::Debug (); use Cpanel::SafeRun::Errors (); use Cpanel::SafeRun::Dynamic (); use Cpanel::Config::LoadCpConf (); use Cpanel::Cron::Utils (); use Cpanel::ServerTasks (); use Cpanel::GenSysInfo (); # Already included in Cpanel::SysPkgs use Try::Tiny; my $REBOOT_NEEDED_FOR_KERNEL_UPDATE_FLAG_FILE = '/var/cpanel/reboot_required_for_kernel_update'; our $DISABLE_INSTALLED_PHPDSO_CACHE = 0; my @Pre = ( sub { return cleanup_php_threaded_mpm(@_) }, sub { return cleanup_php_dso_conflict(@_) }, ); # Determines the threading status of the Apache MPM. It does not execute # the Apache binary because EA4's configuration loads MPMs dynamically. This # means a lot of work would need to be put forth to generate a temporary # configuration and/or execute the current system one (which could be broken). # # NOTE: # Until https://jira.cpanel.net/browse/HB-690 can update # Cpanel::PackMan with the 'provides' information, this code manually # queries the Apache MPM package to determine the threading status. # # USAGE: # If it's unable to determine the threading status, then it returns an empty string # Otherwise, the typical values are 'threaded' and 'forked' sub get_apache_thread_status { my $status = ''; my $mpm_package = Cpanel::SafeRun::Errors::saferunnoerror( q{/bin/rpm}, q{-q}, q{--whatprovides}, q{ea-apache24-mpm}, q{--queryformat}, q/%{name}/ ); if ( $mpm_package && $mpm_package =~ /\Aea\-apache/ ) { my $provides = Cpanel::SafeRun::Errors::saferunnoerror( q{/bin/rpm}, q{-q}, q{--provides}, $mpm_package ); $status = $1 if $provides =~ /ea\-apache24\-mpm\s*=\s*(\w+)/; # e.g. ea-apache24-mpm = threaded } return lc $status; } my $installed_packages_cache; # Retrieve a list of PHP packages that contain the mod_php (libphp5) Apache module sub get_installed_phpdso_packages { my ( $self, $php, $pkm ) = @_; return @$installed_packages_cache if $installed_packages_cache && !$DISABLE_INSTALLED_PHPDSO_CACHE; my @packages; my @want_packages = map { "$_-php" } sort @{ $php->get_installed_packages() }; # oldest to newest for logic below my $results = $pkm->multi_pkg_info( 'disable-excludes' => 1, 'packages' => \@want_packages ); my %installed_packages = map { ( $_->{state} eq 'installed' || $_->{state} eq 'updatable' ) ? ( $_->{package} => 1 ) : () } @{$results}; my @installed = grep { $installed_packages{$_} } @want_packages; $installed_packages_cache = \@installed; return @installed; } # EA-3753: This removes duplicate PHP DSO packages because the Apache # webserver only works correctly if 1 is installed. Older EA4 RPMs # did not enforce this correctly. sub cleanup_php_dso_conflict { my $self = shift; my $pkm = Cpanel::PackMan->instance(); my $php = eval { Cpanel::ProgLang->new( type => 'php' ) }; return 1 unless $php; my @packages = sort $self->get_installed_phpdso_packages( $php, $pkm ); # oldest to newest return 1 unless @packages; # Prefer the default PHP. If that's not set for some reason, then choose the newest. my $default = eval { $php->get_system_default_package() } || $packages[-1]; # could be undef due to bad cfg my $keep = ( grep { $_ eq "$default-php" } @packages ) ? "$default-php" : $packages[-1]; my @erase = grep { $_ ne $keep } @packages; return 1 unless @erase; print locale->maketext("You can only install a single [asis,PHP] [output,acronym,DSO,Dynamically Shared Object] package on the [asis,Apache] webserver."), "\n"; print locale->maketext( "The system will remove the [list_and_quoted,_1] [asis,PHP] [numerate,_2,package,packages].", \@erase, $#erase + 1 ), "\n"; return ( eval { $pkm->sys->uninstall(@erase) } ? 1 : 0 ); } # EA-3954: Need to check if the system has a PHP DSO package installed # while a threaded Apache MPM is in-use. Older EA4 rpms did not # properly conflict. This removes the packages from the system so that # the subsequent yum update will work when the conflict is added after # the update. sub cleanup_php_threaded_mpm { my $self = shift; my $pkm = Cpanel::PackMan->instance(); my $php = eval { Cpanel::ProgLang->new( type => 'php' ) }; return 1 unless $php; my @packages = $self->get_installed_phpdso_packages( $php, $pkm ); return 1 unless @packages; my $thread_status = $self->get_apache_thread_status(); return 1 unless $thread_status eq 'threaded'; print locale->maketext("The [asis,Apache] webserver’s configuration contains a threaded [output,acronym,MPM,Multi-Processing Module]."), "\n"; print locale->maketext( "The system will remove the [list_and_quoted,_1] [asis,PHP] [numerate,_2,package,packages].", \@packages, $#packages + 1 ), "\n"; return ( eval { $pkm->sys->uninstall(@packages) } ? 1 : 0 ); } sub script { my ( $class, @argv ) = @_; exit if ( $^O !~ m/linux/i ); my $self = bless( {}, $class ); my $param = Getopt::Param->new; $_->($self) for @Pre; my $update_conf_ref = Cpanel::Update::Config::load(); if ( $update_conf_ref->{'RPMUP'} eq 'never' ) { print locale->maketext("Not updating [asis,RPMs] because the [asis,RPMUP] option is set to “never”.") . "\n" if $param->get_param('verbose'); exit; } print Cpanel::SafeRun::Dynamic::saferun_callback( 'prog' => ['/usr/local/cpanel/scripts/find_and_fix_rpm_issues'], 'callback' => sub { print $_[0]; } ); die 'Found problems with the RPM database that could not be fixed automatically' if ( $? >> 8 ) > 0; my $cpconf_ref = Cpanel::Config::LoadCpConf::loadcpconf_not_copy(); my $rpmup_allow_kernel = $cpconf_ref->{'rpmup_allow_kernel'}; $rpmup_allow_kernel ||= 0; print Cpanel::SafeRun::Dynamic::saferun_callback( # --nokernel means do not exclude kernel 'prog' => [ '/usr/local/cpanel/scripts/checkyum', $rpmup_allow_kernel ? '--nokernel' : '--kernel' ], 'callback' => sub { print $_[0]; } ); die 'checkyum --kernel exited nonzero' if ( $? >> 8 ) > 0; Cpanel::SysPkgs->new()->update(); # Remove the cache for GenSysInfo and rebuild it (via rename in place), as the update may have been to a new minor version (ex. CentOS 7.3 -> 7.4) { local $Cpanel::GenSysInfo::sys_info_file = $Cpanel::GenSysInfo::sys_info_file . ".new"; Cpanel::GenSysInfo::run(); } rename $Cpanel::GenSysInfo::sys_info_file . ".new", $Cpanel::GenSysInfo::sys_info_file; Cpanel::ServerTasks::schedule_task( ['SystemTasks'], 5, "recache_system_reboot_data" ); # Ensure that the handler for code on reboot is enabled my $root_crontab = Cpanel::Cron::Utils::fetch_user_crontab('root'); if ( $root_crontab !~ /\@reboot\s+\/usr\/local\/cpanel\/bin\/onboot_handler/ ) { $root_crontab .= "\@reboot /usr/local/cpanel/bin/onboot_handler\n"; Cpanel::Cron::Utils::save_root_crontab($root_crontab); } # TODO: Remove this in cPanel & WHM v68 if ( -e $REBOOT_NEEDED_FOR_KERNEL_UPDATE_FLAG_FILE ) { if ( !unlink($REBOOT_NEEDED_FOR_KERNEL_UPDATE_FLAG_FILE) ) { Cpanel::Debug::log_warn("Failed to unlink($REBOOT_NEEDED_FOR_KERNEL_UPDATE_FLAG_FILE): $!"); } } if ( !$rpmup_allow_kernel ) { # Only call checkyum to put back the kernel exclude # if we took it out above. exec '/usr/local/cpanel/scripts/checkyum', '--nokernel' or die "Failed to update /etc/yum.conf"; } return; } unless ( caller() ) { exit( __PACKAGE__->script(@ARGV) ); }