Skip to content

Reboot

Reboot after X-hour

Description: Reboot server to release resources component

Schedule: 55 9,13,19,23 * * *

Because the CRON will always to remember the component at the --:00, so we extracted 5 min each.

Mechanism:

flowchart LR

  subgraph slack[Slack]
    ok_channel[Channel #server]
  end

  subgraph tserver[Target Server]
    direction LR
    subgraph reboot_progress[Reboot Progress]
      direction LR
      pre_release[Send pre-release] --> exec_reboot[Reboot] --> after_release[Send after-release]
    end

    subgraph auth[Authentication]
      auth_vpn[VPN Gateway] --> auth_user[Authentication User]
    end

    auth_user -- trigger --> reboot_progress
  end

  subgraph gha[GitHub Actions]
    schedule[Schedule] -- execute --> ghwf[Workflow]
  end

  ghwf --> tserver
  tserver --> slack

The runner exection reboot required su priviledges and using reboot without the password interactive. So config this into the target server.

/etc/sudoers
<USER> ALL=NOPASSWD:/sbin/reboot

Note: the runner can't not be the same as the runner for component schedule

Structure metadata for reboot:

A. [Required] Identifier of the server:

  • The IPv4 of server. E.g: 172.1.1.2. The IP will be hashed when go to the Slack

Shortcut check in Linux (tested on Centos7)

hostname -I
  • By User: The username that exection the progress

  • Phase of reboot progress: PRE_RELEASE or REBOOT

C. [Optional] The uptime of server since that period

uptime -s
# 2019-07-26 22:16:50

Capture using Python

import subprocess
output = subprocess.run(["uptime", '-s'], capture_output=True)
output.stdout.decode('utf-8').strip()

Verify timezone

ls -l /etc/localtime
# lrwxrwxrwx. 1 root root 38 Oct 14  2022 /etc/localtime -> ../usr/share/zoneinfo/Asia/Ho_Chi_Minh

time.tzname return a tuple of two string: The first is the name of the local non-DST timezone, the second is the name of the local DST timezone.

import time
time.tzname
# ('+07', '+07')
# example

In case of failure, the will be the mayday mayday message to notification for maintainer.