Skip to content

Commit

Permalink
Merge pull request #504 from cpanel/RE-743
Browse files Browse the repository at this point in the history
Convert bash pipeline scripts to PERL.
  • Loading branch information
toddr authored Sep 5, 2024
2 parents d053bd2 + 67e4509 commit 8dcfd78
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 73 deletions.
40 changes: 21 additions & 19 deletions .github/workflows/openstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ jobs:
username: 'root'
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: '22'
timeout: 30m
command_timeout: 30m
script: |
cp -pv /opt/elevate/elevate-cpanel /scripts/elevate-cpanel
cp -pv /opt/elevate/.github/workflows/openstack/status_marker.sh /scripts/status_marker.sh
cp -pv /opt/elevate/.github/workflows/openstack/reboot_watch.sh /scripts/reboot_watch.sh
cp -pv /opt/elevate/.github/workflows/openstack/status_marker /scripts/status_marker
cp -pv /opt/elevate/.github/workflows/openstack/reboot_watch /scripts/reboot_watch
chmod -v +x /scripts/elevate-cpanel
/usr/local/cpanel/cpkeyclt
/scripts/elevate-cpanel --non-interactive --start &
Expand All @@ -169,7 +171,7 @@ jobs:
- name: Wait For VM to Come Back From Stage 2 Reboot
working-directory: "./.github/workflows/openstack/"
run: |
./ssh_retry.sh ${{ needs.start_elevate.outputs.VM_IP }}
./ssh_retry ${{ needs.start_elevate.outputs.VM_IP }}
watch_for_stage_3_reboot:
runs-on: self-hosted
Expand All @@ -185,12 +187,12 @@ jobs:
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: '22'
timeout: 60m
command_timeout: 20m
command_timeout: 30m
debug: true
script: |
/scripts/status_marker.sh 3
/scripts/status_marker 3
/scripts/elevate-cpanel --log &
REGEX="Rebooting into stage 3 of 5" RETVAL=1 /scripts/reboot_watch.sh
REGEX="Rebooting into stage 3 of 5" RETVAL=1 /scripts/reboot_watch
wait_for_stage_3_reboot:
runs-on: self-hosted
Expand All @@ -201,7 +203,7 @@ jobs:
- name: Wait For VM to Come Back From Stage 3 Reboot
working-directory: "./.github/workflows/openstack/"
run: |
./ssh_retry.sh ${{ needs.watch_for_stage_3_reboot.outputs.VM_IP }}
./ssh_retry ${{ needs.watch_for_stage_3_reboot.outputs.VM_IP }}
watch_for_stage_4_reboot:
runs-on: self-hosted
Expand All @@ -217,11 +219,11 @@ jobs:
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: '22'
timeout: 30m
command_timeout: 20m
command_timeout: 30m
script: |
/scripts/status_marker.sh 4
/scripts/status_marker 4
/scripts/elevate-cpanel --log &
REGEX="Rebooting into stage 4 of 5" RETVAL=1 /scripts/reboot_watch.sh
REGEX="Rebooting into stage 4 of 5" RETVAL=1 /scripts/reboot_watch
wait_for_stage_4_reboot:
runs-on: self-hosted
Expand All @@ -232,7 +234,7 @@ jobs:
- name: Wait For VM to Come Back From Stage 4 Reboot
working-directory: "./.github/workflows/openstack/"
run: |
./ssh_retry.sh ${{ needs.watch_for_stage_4_reboot.outputs.VM_IP }}
./ssh_retry ${{ needs.watch_for_stage_4_reboot.outputs.VM_IP }}
watch_for_stage_5_reboot:
runs-on: self-hosted
Expand All @@ -247,12 +249,12 @@ jobs:
username: 'root'
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: '22'
timeout: 30m
command_timeout: 20m
timeout: 45m
command_timeout: 35m
script: |
/scripts/status_marker.sh 5
/scripts/status_marker 5
/scripts/elevate-cpanel --log &
REGEX="Rebooting into stage 5 of 5" RETVAL=1 /scripts/reboot_watch.sh
REGEX="Rebooting into stage 5 of 5" RETVAL=1 /scripts/reboot_watch
wait_for_stage_5_reboot:
runs-on: self-hosted
Expand All @@ -263,7 +265,7 @@ jobs:
- name: Wait For VM to Come Back From Stage 5 Reboot
working-directory: "./.github/workflows/openstack/"
run: |
./ssh_retry.sh ${{ needs.watch_for_stage_5_reboot.outputs.VM_IP }}
./ssh_retry ${{ needs.watch_for_stage_5_reboot.outputs.VM_IP }}
watch_for_final_reboot:
runs-on: self-hosted
Expand All @@ -279,10 +281,10 @@ jobs:
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: '22'
timeout: 30m
command_timeout: 20m
command_timeout: 30m
script: |
/scripts/elevate-cpanel --log &
REGEX="Doing final reboot" RETVAL=1 /scripts/reboot_watch.sh
REGEX="Doing final reboot" RETVAL=1 /scripts/reboot_watch
wait_for_final_reboot:
runs-on: self-hosted
Expand All @@ -293,7 +295,7 @@ jobs:
- name: Wait For VM to Come Back From Final Reboot
working-directory: "./.github/workflows/openstack/"
run: |
./ssh_retry.sh ${{ needs.watch_for_final_reboot.outputs.VM_IP }}
./ssh_retry ${{ needs.watch_for_final_reboot.outputs.VM_IP }}
verify_upgraded_os:
runs-on: self-hosted
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/openstack/reboot_watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/local/cpanel/3rdparty/bin/perl

use constant ELEVATE_LOG_PATH => '/var/log/elevate-cpanel.log';

use Env;

use File::Tail;
use POSIX;

my $RETVAL = 1;
my $RETRIES = 0;

while ( $RETVAL != 0 ) {
_check_elevate_log_for_regex( ELEVATE_LOG_PATH, ${REGEX}, $RETRIES );
}

sub _check_elevate_log_for_regex {
my ( $filepath, $REGEX, $RETRIES ) = @_;

my $time = POSIX::strftime( "%Y-%m-%d %H:%M:%S", localtime );

$file = File::Tail->new( name => $filepath, maxinterval => 1, adjustafter => 7, interval => 1 );
while ( defined( $line = $file->read ) ) {
if ( grep { /$REGEX/m } $line ) {
print "## [$time] [INFO]: SUCCESS: Reboot regex ( $REGEX ) found in /var/log/elevate-cpanel.log ##\n";
exit 0;
}
$RETRIES++;
}
}
10 changes: 0 additions & 10 deletions .github/workflows/openstack/reboot_watch.sh

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/openstack/ssh_retry
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env perl

use POSIX;

my $HOST = $ARGV[0];
my $PORT = $ARGV[1] // 22;
my $RETVAL = 1;
my $RETRIES = 0;
my $RETRY = $ARGV[2] // 60;

return unless defined $HOST;

while ( $RETVAL != 0 ) {
my $cmd = qq{ /usr/bin/nc -z -w 3 $HOST $PORT };
my $output = `$cmd`;
my $time = POSIX::strftime( "%Y-%m-%d %H:%M:%S", localtime );

$RETVAL = $?;

if ( $RETVAL == 0 ) {
print "## [$time] [INFO] SUCCESS: Connected to SSH on $HOST ##\n";
exit 0;
}

$RETRIES++;

if ( $RETVAL != 0 ) {
print "## [$time] [INFO]: Retrying SSH Connect: Attempt ${RETRIES} ...\n";
}

if ( $RETRIES >= $RETRY ) {
print "## [$time] [ERROR]: ssh_retry.pl: MAX_RETRIES has been reached.\n";
exit 1;
}
sleep 15;
}
27 changes: 0 additions & 27 deletions .github/workflows/openstack/ssh_retry.sh

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/openstack/status_marker
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env perl

my $STAGE = $ARGV[0];
my $RELEASE_INFO = `cat /etc/redhat-release`;
my $CPANEL_VERSION = `cat /usr/local/cpanel/version`;

use strict;

print "######################################\n";

sub main {
my @arr = (
[ 'Stage:', $STAGE ], [ 'OS Release:', $RELEASE_INFO ]
, [ 'cP Version:', $CPANEL_VERSION ]
);

for my $row (@arr) {
format STDOUT =
@<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<
@$row
.
write;
}

}

main();

print "######################################\n";
17 changes: 0 additions & 17 deletions .github/workflows/openstack/status_marker.sh

This file was deleted.

0 comments on commit 8dcfd78

Please sign in to comment.