forked from cpanel/elevate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elevate-cpanel
executable file
·9531 lines (6813 loc) · 282 KB
/
elevate-cpanel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/local/cpanel/3rdparty/bin/perl
## ----------------------------------------------------------------------------
##
## DO NOT EDIT THIS FILE
##
## This file is automatically generated from script/elevate-cpanel.PL
##
## view https://github.com/cpanel/elevate for more details
##
## ----------------------------------------------------------------------------
BEGIN { # Suppress load of all of these at earliest point.
$INC{'Elevate/Constants.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/Base.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/AbsoluteSymlinks.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/BootKernel.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/CloudLinux.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/Databases.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/DiskSpace.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/Distros.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/DNS.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/EA4.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/ElevateScript.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/Grub2.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/Imunify.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/IsContainer.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/JetBackup.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/MountPoints.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/NICs.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/OVH.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/Repositories.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/SSH.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/WHM.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/Leapp.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Blockers/AutoSSL.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/Base.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/AbsoluteSymlinks.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/CCS.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/cPanelPlugins.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/cPanelPrep.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/EA4.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/Grub2.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/Imunify.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/InfluxDB.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/JetBackup.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/LiteSpeed.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/KernelCare.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/Kernel.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/MySQL.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/NICs.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/NixStats.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/PECL.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/PerlXS.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/UnconvertedModules.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/Repositories.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/RpmDB.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/RmMod.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/WPToolkit.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/SSH.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/AutoSSL.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/DatabaseUpgrade.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/ELS.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/R1Soft.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/OS.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/OS/CentOS7.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/OS/CloudLinux7.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/OS/RHEL.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Database.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/EA4.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Fetch.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Leapp.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Logger.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Marker.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Motd.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/NICs.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Notify.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Roles/Run.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/RPM.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Script.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Service.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/StageFile.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Stages.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/SystemctlService.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Usage.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/DNF.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/YUM.pm'} = 'script/elevate-cpanel.PL.static';
}
{ # --- BEGIN lib/Elevate/Constants.pm
package Elevate::Constants;
use cPstrict;
use constant MINIMUM_LTS_SUPPORTED => 110;
use constant MAXIMUM_LTS_SUPPORTED => 110;
use constant SERVICE_DIR => '/etc/systemd/system/';
use constant SERVICE_NAME => 'elevate-cpanel.service';
use constant LOG_FILE => q[/var/log/elevate-cpanel.log];
use constant PID_FILE => q[/var/run/elevate-cpanel.pid];
use constant DEFAULT_GRUB_FILE => '/etc/default/grub';
use constant YUM_REPOS_D => q[/etc/yum.repos.d];
use constant ELEVATE_BACKUP_DIR => "/root/.elevate.backup";
use constant IMUNIFY_AGENT => '/usr/bin/imunify360-agent';
use constant CHKSRVD_SUSPEND_FILE => q[/var/run/chkservd.suspend];
use constant IGNORE_OUTDATED_SERVICES_FILE => q[/etc/cpanel/local/ignore_outdated_services];
use constant SBIN_IP => q[/sbin/ip];
use constant ETH_FILE_PREFIX => q[/etc/sysconfig/network-scripts/ifcfg-];
use constant R1SOFT_REPO => 'r1soft';
use constant R1SOFT_REPO_FILE => '/etc/yum.repos.d/r1soft.repo';
use constant R1SOFT_MAIN_AGENT_PACKAGE => 'serverbackup-agent';
use constant R1SOFT_AGENT_PACKAGES => qw{
r1soft-getmodule
serverbackup-agent
serverbackup-async-agent-2-6
serverbackup-enterprise-agent
serverbackup-setup
};
1;
} # --- END lib/Elevate/Constants.pm
{ # --- BEGIN lib/Elevate/Blockers/Base.pm
package Elevate::Blockers::Base;
use cPstrict;
use Carp ();
use Cpanel::JSON ();
use Simple::Accessor qw(
blockers
yum
);
# use Log::Log4perl qw(:easy);
INIT { Log::Log4perl->import(qw{:easy}); }
sub _build_blockers {
if ( $0 =~ qr{\bt/} ) {
return Elevate::Blockers->new;
}
Carp::confess(q[Missing blockers]);
}
sub _build_yum ($self) {
return Elevate::YUM->new( cpev => $self );
}
sub cpev ($self) {
return $self->blockers->cpev;
}
BEGIN {
my @_DELEGATE_TO_CPEV = qw{
getopt
upgrade_to_pretty_name
should_run_leapp
ssystem
ssystem_capture_output
ssystem_hide_and_capture_output
};
foreach my $subname (@_DELEGATE_TO_CPEV) {
no strict 'refs';
*$subname = sub ( $self, @args ) {
my $cpev = $self->cpev or Carp::confess(qq[Cannot find cpev object to call function $subname]);
my $sub = $cpev->can($subname) or Carp::confess(qq[cpev does not support $subname]);
return $sub->( $cpev, @args );
}
}
}
sub is_check_mode ( $self, @args ) {
return $self->blockers->is_check_mode(@args);
}
sub has_blocker ( $self, $msg, %others ) {
my $caller_id;
if ( $others{'blocker_id'} ) {
$caller_id = $others{'blocker_id'};
}
else {
( undef, undef, undef, $caller_id ) = caller(1);
$caller_id ||= ref $self;
}
my $analytics_data;
if ( $others{info} ) {
my $info = delete $others{info};
if ( ref $info eq 'HASH' ) {
$analytics_data = Cpanel::JSON::canonical_dump( [$info] );
}
else {
my ( $latest_version, $self_version ) = ( $self->cpev->script->latest_version(), cpev::VERSION() );
if ( $self_version > $latest_version ) {
die "Invalid data analytics given to blocker. 'info' must be a hash reference.\n";
}
}
}
my $blocker = cpev::Blocker->new( id => $caller_id, msg => $msg, %others, info => $analytics_data );
$self->blockers->add_blocker($blocker);
die $blocker if $self->blockers->abort_on_first_blocker();
if ( !$others{'quiet'} ) {
WARN( <<~"EOS");
*** Elevation Blocker detected: ***
$msg
EOS
}
return $blocker;
}
{
package cpev::Blocker;
use Simple::Accessor qw{ id msg info };
sub TO_JSON ($self) {
my %hash = $self->%*;
return \%hash;
}
}
1;
} # --- END lib/Elevate/Blockers/Base.pm
{ # --- BEGIN lib/Elevate/Blockers.pm
package Elevate::Blockers;
use cPstrict;
use Elevate::Blockers::Base ();
use Elevate::Blockers::AbsoluteSymlinks ();
use Elevate::Blockers::CloudLinux ();
use Elevate::Blockers::Databases ();
use Elevate::Blockers::DiskSpace ();
use Elevate::Blockers::Distros ();
use Elevate::Blockers::DNS ();
use Elevate::Blockers::EA4 ();
use Elevate::Blockers::Grub2 ();
use Elevate::Blockers::Imunify ();
use Elevate::Blockers::IsContainer ();
use Elevate::Blockers::JetBackup ();
use Elevate::Blockers::MountPoints ();
use Elevate::Blockers::NICs ();
use Elevate::Blockers::OVH ();
use Elevate::Blockers::ElevateScript ();
use Elevate::Blockers::SSH ();
use Elevate::Blockers::WHM ();
use Elevate::Blockers::Repositories ();
use Simple::Accessor qw(
cpev
check_mode
blockers
abort_on_first_blocker
);
# use Log::Log4perl qw(:easy);
INIT { Log::Log4perl->import(qw{:easy}); }
use Cpanel::JSON ();
our @BLOCKERS = qw{
IsContainer
ElevateScript
MountPoints
SSH
DiskSpace
WHM
Distros
CloudLinux
Imunify
DNS
Databases
Repositories
JetBackup
NICs
EA4
BootKernel
Grub2
OVH
AbsoluteSymlinks
AutoSSL
};
push @BLOCKERS, 'Leapp'; # This blocker has to run last!
use constant ELEVATE_BLOCKER_FILE => '/var/cpanel/elevate-blockers';
our $_CHECK_MODE; # for now global so we can use the helper (move it later to the object)
sub _build_blockers { return []; }
sub check ($self) { # do_check - main entry point
if ( $self->cpev->service->is_active ) {
WARN("An elevation process is already in progress.");
return 1;
}
my $stage = Elevate::Stages::get_stage();
if ( $stage != 0 && $stage <= cpev::VALID_STAGES() ) {
die <<~"EOS";
An elevation process is currently in progress: running stage $stage
You can check the log by running:
/scripts/elevate-cpanel --log
or check the elevation status:
/scripts/elevate-cpanel --status
EOS
}
Elevate::Blockers::Distros::bail_out_on_inappropriate_distro();
my $blocker_file = $self->cpev->getopt('check') || ELEVATE_BLOCKER_FILE;
my $has_blockers = $self->_has_blockers( $self->cpev->getopt('start') ? 0 : 1 );
$self->save( $blocker_file, { 'blockers' => $self->{'blockers'} } );
if ($has_blockers) {
WARN( <<~'EOS' );
Please fix the detected issues before performing the elevation process.
Read More: https://cpanel.github.io/elevate/blockers/
EOS
}
else {
my $cmd = q[/scripts/elevate-cpanel --start];
INFO( <<~"EOS" );
There are no known blockers to start the elevation process.
You can consider running:
$cmd
EOS
}
return $has_blockers;
}
sub _has_blockers ( $self, $check_mode = 0 ) {
unless ( $< == 0 ) {
ERROR("This script can only be run by root");
return 666;
}
$_CHECK_MODE = !!$check_mode; # running with --check
$self->abort_on_first_blocker(0);
my $ok = eval { $self->_check_all_blockers; 1; };
if ( !$ok ) {
my $error = $@;
if ( ref $error eq 'cpev::Blocker' ) {
ERROR( $error->{msg} );
return 401;
}
WARN("Unknown error while checking blockers: $error");
return 127; # unknown error
}
return scalar $self->blockers->@*;
}
sub num_blockers_found ($self) {
return scalar $self->blockers->@*;
}
sub add_blocker ( $self, $blocker ) {
push $self->blockers->@*, $blocker;
return;
}
sub is_check_mode ($) {
return $_CHECK_MODE;
}
sub save ( $self, $path, $stash ) {
open( my $fh, '>', $path ) or LOGDIE( "Failed to open " . $path . ": $!" );
print {$fh} Cpanel::JSON::pretty_canonical_dump($stash);
close $fh;
return 1;
}
sub _check_all_blockers ($self) { # sub _blockers_check ($self) {
foreach my $blocker (@BLOCKERS) { # preserve order
$self->_check_single_blocker($blocker);
}
return 0;
}
sub _check_single_blocker ( $self, $name ) {
my $blocker = $self->_get_blocker_for($name);
my $check = $blocker->can('check')
or die qq[Missing check function from ] . ref($blocker);
return $check->($blocker);
}
sub _get_blocker_for ( $self, $name ) { # useful for tests
my $pkg = "Elevate::Blockers::$name"; # need to be loaded
return $pkg->new( blockers => $self );
}
1;
} # --- END lib/Elevate/Blockers.pm
{ # --- BEGIN lib/Elevate/Blockers/AbsoluteSymlinks.pm
package Elevate::Blockers::AbsoluteSymlinks;
use cPstrict;
use Elevate::Components::AbsoluteSymlinks ();
# use Log::Log4perl qw(:easy);
INIT { Log::Log4perl->import(qw{:easy}); }
# use Elevate::Blockers::Base();
our @ISA;
BEGIN { push @ISA, qw(Elevate::Blockers::Base); }
sub check ($self) {
my %links = Elevate::Components::AbsoluteSymlinks::get_abs_symlinks();
WARN( "Symlinks with absolute paths have been found in /:\n\t" . join( ", ", sort keys(%links) ) . "\n" . "This can cause problems during the leapp run, so\n" . 'these will be corrected to be relative symlinks before elevation.' ) if %links;
return;
}
1;
} # --- END lib/Elevate/Blockers/AbsoluteSymlinks.pm
{ # --- BEGIN lib/Elevate/Blockers/BootKernel.pm
package Elevate::Blockers::BootKernel;
use cPstrict;
# use Elevate::Blockers::Base();
our @ISA;
BEGIN { push @ISA, qw(Elevate::Blockers::Base); }
use Elevate::Constants ();
use Cpanel::Kernel::Status ();
use Cpanel::Exception ();
use Cpanel::YAML ();
use Cpanel::JSON ();
use Try::Tiny;
sub check ($self) {
return 1 unless $self->should_run_leapp; # skip when --no-leapp is provided
my $ok = 0;
try {
my ( $running_version, $boot_version ) = Cpanel::Kernel::Status::reboot_status()->@{ 'running_version', 'boot_version' };
$ok = $running_version eq $boot_version;
$self->has_blocker( <<~EOS ) if !$ok;
The running kernel version ($running_version) does not match that of
the default boot entry ($boot_version). This could be due to the kernel
being changed by an update, meaning that a reboot should resolve this.
However, this also could indicate that the system does not have control
over which kernel and early boot environment (initrd) is used upon
reboot, which is required to upgrade the operating system with this
script.
If this message remains after a reboot, your server may have been
configured to boot into a particular kernel directly rather than to an
instance of the GRUB2 boot loader. This often happens to virtualized
servers, but physical servers also can have this problem under certain
configurations. Your provider may have a solution to allow booting into
GRUB2; contact them for further information.
EOS
}
catch {
my $ex = $_;
$self->has_blocker(
"Unable to determine running and boot kernels due to the following error:\n" #
. _to_str($ex)
);
};
return $ok ? 1 : 0;
}
sub _to_str ($e) {
$e //= '';
my $str = Cpanel::Exception::get_string($e);
if ( length $str ) {
my $hash = eval { Cpanel::YAML::Load($str) } # parse yaml
// eval { Cpanel::JSON::Load($str) } # or json output... we cannot predict
// {};
if ( ref $hash eq 'HASH' && $hash->{msg} ) {
$str = $hash->{msg};
}
}
return $str;
}
1;
} # --- END lib/Elevate/Blockers/BootKernel.pm
{ # --- BEGIN lib/Elevate/Blockers/CloudLinux.pm
package Elevate::Blockers::CloudLinux;
use cPstrict;
# use Elevate::Blockers::Base();
our @ISA;
BEGIN { push @ISA, qw(Elevate::Blockers::Base); }
use Elevate::OS ();
# use Log::Log4perl qw(:easy);
INIT { Log::Log4perl->import(qw{:easy}); }
use constant CLDETECT => '/usr/bin/cldetect';
use constant RHN_CHECK => '/usr/sbin/rhn_check';
sub check ($self) {
return $self->_check_cloudlinux_license();
}
sub _check_cloudlinux_license ($self) {
return 0 unless Elevate::OS::should_check_cloudlinux_license();
my $out = $self->ssystem_capture_output( CLDETECT, '--check-license' );
if ( $self->ssystem(RHN_CHECK) != 0 || $out->{status} != 0 || grep { $_ !~ m/^ok/i } @{ $out->{stdout} } ) {
$self->blockers->abort_on_first_blocker(1);
return $self->has_blocker( <<~'EOS');
The CloudLinux license is reporting that it is not currently valid. A
valid CloudLinux license is required to ELevate from CloudLinux 7 to
CloudLinux 8.
EOS
}
return 0;
}
1;
} # --- END lib/Elevate/Blockers/CloudLinux.pm
{ # --- BEGIN lib/Elevate/Blockers/Databases.pm
package Elevate::Blockers::Databases;
use cPstrict;
use Elevate::Database ();
use Elevate::StageFile ();
use Cpanel::OS ();
use Cpanel::Pkgr ();
use Cpanel::Version::Tiny ();
use Cpanel::JSON ();
use Cpanel::SafeRun::Simple ();
use Cpanel::DB::Map::Collection::Index ();
use Cpanel::Exception ();
use Cpanel::MysqlUtils::MyCnf::Basic ();
# use Elevate::Blockers::Base();
our @ISA;
BEGIN { push @ISA, qw(Elevate::Blockers::Base); }
# use Log::Log4perl qw(:easy);
INIT { Log::Log4perl->import(qw{:easy}); }
use constant POSTGRESQL_ACK_TOUCH_FILE => q[/var/cpanel/acknowledge_postgresql_for_elevate];
sub check ($self) {
my $ok = 1;
$self->_warning_if_postgresql_installed;
$ok = 0 unless $self->_blocker_acknowledge_postgresql_datadir;
$ok = 0 unless $self->_blocker_remote_mysql;
$ok = 0 unless $self->_blocker_old_mysql;
$ok = 0 unless $self->_blocker_mysql_upgrade_in_progress;
$self->_warning_mysql_not_enabled();
return $ok;
}
sub _warning_if_postgresql_installed ($self) {
return 0 unless Cpanel::Pkgr::is_installed('postgresql-server');
my $pg_full_ver = Cpanel::Pkgr::get_package_version('postgresql-server');
my ($old_version) = $pg_full_ver =~ m/^(\d+\.\d+)/a;
return 1 if !$old_version || $old_version >= 10;
my $pretty_distro_name = $self->upgrade_to_pretty_name();
WARN("You have postgresql-server version $old_version installed. This will be upgraded irreversibly to version 10.0 when you switch to $pretty_distro_name");
return 2;
}
sub _blocker_acknowledge_postgresql_datadir ($self) {
return 0 unless Cpanel::Pkgr::is_installed('postgresql-server');
my $touch_file = POSTGRESQL_ACK_TOUCH_FILE;
return 0 if -e $touch_file;
my @users_with_dbs = $self->_has_mapped_postgresql_dbs();
return 0 unless scalar @users_with_dbs;
my $message = <<~"EOS";
One or more users on your system have associated PostgreSQL databases.
ELevate may upgrade the software packages associated with PostgreSQL
automatically, but if it does, it will *NOT* automatically update the
PostgreSQL data directory to work with the new version. Without an update
to the data directory, the upgraded PostgreSQL software will not start, in
order to ensure that your data does not become corrupted.
For more information about PostgreSQL upgrades, please consider the
following resources:
https://cpanel.github.io/elevate/blockers/#postgresql
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/deploying_different_types_of_servers/using-databases#migrating-to-a-rhel-8-version-of-postgresql_using-postgresql
https://www.postgresql.org/docs/10/pgupgrade.html
When you are ready to acknowledge that you have prepared to update the
PostgreSQL data directory, or that this warning does not apply to you,
please touch the following file to continue with the ELevate process:
> touch $touch_file
The following user(s) have PostgreSQL databases associated with their cPanel accounts:
EOS
$message .= join "\n", sort(@users_with_dbs);
return $self->has_blocker($message);
}
sub _has_mapped_postgresql_dbs ($self) {
my $dbindex = eval { Cpanel::DB::Map::Collection::Index->new( { db => 'PGSQL' } ); };
if ( my $exception = $@ ) {
ERROR( 'Unable to read the database index file: ' . Cpanel::Exception::get_string($exception) );
$self->has_blocker("Unable to read the database index file; you may need to rebuild it by running: /usr/local/cpanel/bin/dbindex");
return ();
}
my %user_hash = map { $dbindex->{dbindex}{$_} => 1 } keys %{ $dbindex->{dbindex} };
return ( keys %user_hash );
}
sub _blocker_remote_mysql ($self) {
my $pretty_distro_name = $self->upgrade_to_pretty_name();
if ( Cpanel::MysqlUtils::MyCnf::Basic::is_remote_mysql() ) {
return $self->has_blocker( <<~"EOS" );
The system is currently setup to use a remote database server.
We cannot elevate the system to $pretty_distro_name
unless the system is configured to use the local database server.
EOS
}
return 0;
}
sub _blocker_old_mysql ($self) {
my $mysql_is_provided_by_cloudlinux = Elevate::Database::is_database_provided_by_cloudlinux(0);
return $mysql_is_provided_by_cloudlinux ? $self->_blocker_old_cloudlinux_mysql() : $self->_blocker_old_cpanel_mysql();
}
sub _blocker_old_cloudlinux_mysql ($self) {
my ( $db_type, $db_version ) = Elevate::Database::get_db_info_if_provided_by_cloudlinux();
return 0 if length $db_version && $db_version >= 55;
my $pretty_distro_name = $self->upgrade_to_pretty_name();
my $db_dot_version = $db_version;
$db_dot_version =~ s/([0-9])$/\.$1/;
return $self->has_blocker( <<~"EOS");
You are using MySQL $db_dot_version server.
This version is not available for $pretty_distro_name.
You first need to update your MySQL server to 5.5 or later.
Please review the following documentation for instructions
on how to update to a newer MySQL Version with MySQL Governor:
https://docs.cloudlinux.com/shared/cloudlinux_os_components/#upgrading-database-server
Once the MySQL upgrade is finished, you can then retry to elevate to $pretty_distro_name.
EOS
}
sub _blocker_old_cpanel_mysql ($self) {
my $mysql_version = Elevate::Database::get_local_database_version();
if ( Elevate::Database::is_database_version_supported($mysql_version) ) {
Elevate::StageFile::update_stage_file( { 'mysql-version' => $mysql_version } );
return 0;
}
my $pretty_distro_name = $self->upgrade_to_pretty_name();
my $database_type_name = Elevate::Database::get_database_type_name_from_version($mysql_version);
my $upgrade_version = Elevate::Database::get_default_upgrade_version();
my $upgrade_dbtype_name = Elevate::Database::get_database_type_name_from_version($upgrade_version);
WARN( <<~"EOS" );
You have $database_type_name $mysql_version installed.
This version is not available for $pretty_distro_name.
EOS
if ( $self->is_check_mode() ) {
INFO( <<~"EOS" );
You can manually upgrade your installation of $database_type_name using the following command:
/usr/local/cpanel/bin/whmapi1 start_background_mysql_upgrade version=$upgrade_version
Once the MySQL upgrade is finished, you can then retry to elevate to $pretty_distro_name.
EOS
return 0;
}
WARN( <<~"EOS" );
Prior to elevating this system to $pretty_distro_name,
we will automatically upgrade your installation of $database_type_name
to $upgrade_dbtype_name $upgrade_version.
EOS
if ( !$self->getopt('non-interactive') ) {
if (
!IO::Prompt::prompt(
'-one_char',
'-yes_no',
'-tty',
-default => 'y',
"Do you consent to upgrading to $upgrade_dbtype_name $upgrade_version [Y/n]: ",
)
) {
return $self->has_blocker( <<~"EOS" );
The system cannot be elevated to $pretty_distro_name until $database_type_name has been upgraded. To upgrade manually:
/usr/local/cpanel/bin/whmapi1 start_background_mysql_upgrade version=$upgrade_version
To have have this script perform the upgrade, run this script again and consent to allow it to upgrade $upgrade_dbtype_name $upgrade_version.
EOS
}
}
Elevate::StageFile::update_stage_file( { 'mysql-version' => $upgrade_version } );
return 0;
}
sub _blocker_mysql_upgrade_in_progress ($self) {
if ( -e q[/var/cpanel/mysql_upgrade_in_progress] ) {
return $self->has_blocker(q[MySQL upgrade in progress. Please wait for the MySQL upgrade to finish.]);
}
return 0;
}
sub _warning_mysql_not_enabled ($self) {
require Cpanel::Services::Enabled;
my $enabled = Cpanel::Services::Enabled::is_enabled('mysql');
Elevate::StageFile::update_stage_file( { 'mysql-enabled' => $enabled } );
WARN( "MySQL is disabled. This must be enabled for MySQL upgrade to succeed.\n" . "We temporarily will enable it when it is needed to be enabled,\n" . "but we reccomend starting the process with MySQL enabled." ) if !$enabled;
return 0;
}
1;
} # --- END lib/Elevate/Blockers/Databases.pm
{ # --- BEGIN lib/Elevate/Blockers/DiskSpace.pm
package Elevate::Blockers::DiskSpace;
use cPstrict;
use Cpanel::SafeRun::Simple ();
# use Elevate::Blockers::Base();
our @ISA;
BEGIN { push @ISA, qw(Elevate::Blockers::Base); }
# use Log::Log4perl qw(:easy);
INIT { Log::Log4perl->import(qw{:easy}); }
use constant K => 1;
use constant MEG => 1_024 * K;
use constant GIG => 1_024 * MEG;
sub check ($self) { # $self is a cpev object here
my $ok = _disk_space_check($self);
$self->has_blocker(q[disk space issue]) unless $ok;
return $ok;
}
sub _disk_space_check ($self) {
my $need_space = {
'/boot' => 120 * MEG,
'/usr/local/cpanel' => 1.5 * GIG, #
'/var/lib' => 5 * GIG,
};
my @keys = ( sort keys %$need_space );
my @df_cmd = ( qw{/usr/bin/df -k}, @keys );
my $cmd = join( ' ', @df_cmd );
my $result = Cpanel::SafeRun::Simple::saferunnoerror(@df_cmd) // '';
die qq[Failed to check disk space using: $cmd\n] if $?;
my ( $header, @out ) = split( "\n", $result );
if ( scalar @out != scalar @keys ) {
my $count_keys = scalar @keys;
my $count_out = scalar @out;
die qq[Fail: Cannot parse df output from: $cmd\n] . "# expected $count_keys lines ; got $count_out lines\n" . join( "\n", @out ) . "\n";
}
my @errors;
my $ix = 0;
foreach my $line (@out) {
my $key = $keys[ $ix++ ];
my ( undef, undef, undef, $available ) = split( /\s+/, $line );
my $need = $need_space->{$key};
next if $available > $need;
my $str;
if ( $need / GIG > 1 ) {
$str = sprintf( "- $key needs %2.2f G => available %2.2f G", $need / GIG, $available / GIG );
}
else {
$str = sprintf( "- $key needs %d M => available %d M", $need / MEG, $available / MEG );
}
push @errors, $str;
}
return 1 unless @errors;
my $details = join( "\n", @errors );
my $pretty_distro_name = $self->upgrade_to_pretty_name();
my $error = <<"EOS";
** Warning **: your system does not have enough disk space available to update to $pretty_distro_name
$details
EOS
warn $error . "\n";
return 0; # error
}
1;
} # --- END lib/Elevate/Blockers/DiskSpace.pm
{ # --- BEGIN lib/Elevate/Blockers/Distros.pm
package Elevate::Blockers::Distros;
use cPstrict;
use Cpanel::OS ();
use constant MINIMUM_CENTOS_7_SUPPORTED => 9;
# use Elevate::Blockers::Base();
our @ISA;
BEGIN { push @ISA, qw(Elevate::Blockers::Base); }
use Elevate::OS ();
# use Log::Log4perl qw(:easy);
INIT { Log::Log4perl->import(qw{:easy}); }
sub check ($self) {
my @checks = qw{
_blocker_os_is_not_supported
_blocker_is_old_centos7
_blocker_is_experimental_os
};
foreach my $name (@checks) {
my $blocker = $self->can($name)->($self);
return $blocker if $blocker;
}
return 0;
}
sub _blocker_os_is_not_supported ($self) {
Elevate::OS::is_supported(); # dies
return 0;
}
sub _blocker_is_old_centos7 ($self) {
if ( Cpanel::OS::minor() < MINIMUM_CENTOS_7_SUPPORTED ) { ## no critic(Cpanel::CpanelOS)
my $pretty_distro_name = $self->upgrade_to_pretty_name();
return $self->has_blocker(
sprintf(
'You need to run CentOS 7.%s and later to upgrade %s. You are currently using %s', #
MINIMUM_CENTOS_7_SUPPORTED, $pretty_distro_name, Cpanel::OS::display_name() #
)
);
}
return 0;
}
sub _blocker_is_experimental_os ($self) {
if ( -e '/var/cpanel/caches/Cpanel-OS.custom' ) {
return $self->has_blocker('Experimental OS detected. This script only supports CentOS 7 upgrades');
}
return 0;
}
sub bail_out_on_inappropriate_distro () {
Elevate::OS::clear_cache();
Elevate::OS::is_supported(); # dies
return;
}
1;
} # --- END lib/Elevate/Blockers/Distros.pm
{ # --- BEGIN lib/Elevate/Blockers/DNS.pm
package Elevate::Blockers::DNS;
use cPstrict;
use Elevate::Constants ();