Skip to content

custom_restart

custom_restart #80

name: Configure RHEL 8 Equinix Server
on:
repository_dispatch:
types: [custom_restart]
workflow_dispatch:
inputs:
hostname:
description: 'hostname'
required: true
default: hostname
target_server:
description: 'target_server'
required: true
default: rhel8-equinix
forwarder:
description: 'forwarder'
required: true
default: 1.1.1.1
domain:
description: 'domain'
required: true
default: example.com
env:
TARGET_SERVER: ${{ inputs.target_server }}
DOMAIN: ${{ inputs.domain }}
FORWARDER: ${{ inputs.forwarder }}
ACTIVE_BRIDGE: 'false'
INTERFACE: 'bond0'
jobs:
configure-rhel8-equinix:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- name: Configure RHEL 8 Equinix Server
uses: appleboy/[email protected]
with:
host: ${{ inputs.hostname }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
command_timeout: 30m
script: |
sudo yum install -y git
if [ -d "/opt/quibinode_navigator" ]; then
cd /opt/quibinode_navigator
git config --global --add safe.directory /opt/quibinode_navigator
git config pull.rebase false
git pull
else
cd /opt/
sudo usermod -aG users ${{ secrets.USERNAME }}
sudo chown -R root:users /opt
sudo chmod -R g+w /opt
git clone https://github.com/tosin2013/quibinode_navigator.git
fi
echo "export CICD_PIPELINE=true" > /opt/quibinode_navigator/.env
echo "export SSH_PASSWORD=${{ secrets.SSH_PASSWORD }}" >> /opt/quibinode_navigator/.env
echo "export INVENTORY='${{ env.TARGET_SERVER }}'" >> /opt/quibinode_navigator/.env
echo "export ENV_USERNAME=${{ secrets.USERNAME }}" >> /opt/quibinode_navigator/.env
echo "export DOMAIN=${{ env.DOMAIN }}" >> /opt/quibinode_navigator/.env
echo "export FORWARDER=${{ env.FORWARDER }}" >> /opt/quibinode_navigator/.env
echo "export ACTIVE_BRIDGE=${{ env.ACTIVE_BRIDGE }}" >> /opt/quibinode_navigator/.env
echo "export INTERFACE=${{ env.INTERFACE }}" >> /opt/quibinode_navigator/.env
exit 1
source /opt/quibinode_navigator/.env && sudo -E /opt/quibinode_navigator/rhel8-linux-hypervisor.sh || exit $?
- name: Send a repository dispatch event to restart the workflow if it failed
if: ${{ failure() }}
uses: actions/github-script@v3
with:
github-token: ${{ secrets.PAT }}
script: |
async function run() {
try {
await github.repos.createDispatchEvent({
owner: context.repo.owner,
repo: context.repo.repo,
event_type: "custom_restart",
client_payload: {
data_key: {
hostname: '${{ inputs.hostname }}', // Replace with actual dynamic value if needed
target_server: '${{ env.TARGET_SERVER }}',
forwarder: '${{ env.DOMAIN }}',
domain: '${{ env.DOMAIN }}'
}
}
});
core.info("Restart dispatched");
} catch (error) {
core.setFailed(`Dispatch failed: ${error.message}`);
}
}
run();