Steem Admin Tools / Smooth Server Update & Reboot Script

in #admin3 years ago (edited)


Description


This is an update of my 'Smooth Server Reboot' bash script. It is now able to wait for the exit of multiple processes, update & clean up the linux system and reboot the machine after confirming with [ENTER].

I highly recommend to never update your server with apt update before closing any running steemd processes! If your node runs in a docker image (not as service) and apt updates your docker version, all running processes inside the container may be killed immediately, which eventually will corrupt the RocksDB files.

With this updated version the script will ensure to execute the mentioned tasks always in the right order.

Bash Script


#!/bin/bash

proc_names=("node" "steemd")

function showInfo()
{
    printf "\n$1\n"
    printf "%*s\n\n" "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
}

function installUpdates()
{
    apt update && apt upgrade -y
}

function cleanSystem()
{
    apt autoremove -y
}

function checkProcesses()
{
    proc_ids=($(pidof $1))
    proc_count=${#proc_ids[@]}
}

function closeProcesses()
{
    proc_name=$1

    checkProcesses $proc_name
    for (( i=0; i<$proc_count; i++ ));
    do
        echo "Found process with id: ${proc_ids[$i]}. Sending SIGINT..."
        kill -SIGINT ${proc_ids[$i]}
    done

    while [ $proc_count -gt 0 ]
    do
        echo "$proc_count process(es) still running. Waiting for close..."
        sleep 3
        checkProcesses $proc_name
    done

    echo "No running processes found."
}

clear

for (( p=0; p<${#proc_names[@]}; p++ ));
do
    proc_name=${proc_names[$p]}
    showInfo "Closing '$proc_name' processes..."
    closeProcesses $proc_name
done

showInfo "Running updates..."
installUpdates

showInfo "Cleaning system..."
cleanSystem

showInfo "Rebooting system..."
read -s -N 1 -p "Press [ENTER] to reboot the system or any other key to abort..." key
if [[ $key == $'\x0a' ]];
then
    printf "\nRebooting...\n\n"
    reboot
else
    printf "\nReboot cancelled.\n\n"
fi

Just store the script in a file 'smooth_update_and_reboot.sh' on your server, add execution rights with
chmod +x smooth_update_and_reboot.sh
and you are good to go.

In its current state the script will close all node and steemd processes before updating the system. Of course, the processes to be closed can be changed simply by defining them in the line
proc_names=("node" "steemd").

The script can also be downloaded directly here:
steemworld.org/dl/smooth_update_and_reboot.sh

I hope this helps Steem witnesses and node maintainers in general to be able to update and reboot their system more smoothly :)

Terminal Output


Steem On!


If you like what I do and you want me to be your Steem witness,
please vote for @steemchiller on steemit.com/~witnesses or steemworld.org/witnesses.


Sort:  

Hi, @steemchiller. Hope you are fine.

I've noticed that steemworld.org is suddenly not updating the "Account Operations". At first, I thought it is a temporary bug. But it's been 3 hours, still there is no improvement. I couldn't figure out the issue so I came here. You know its a very important dapp for us, Steemians!

Hope you look into the issue. Waiting for it to be normal again. Thanks!

Thanks for the info! I'm currently updating my servers and it looks like the connection to the steemd instance on that one was broken for a while. It now should work again ;)

yup its working now, Thank You So Much 💚

Hello @steemchiller! I would like to setup a Steem witness, but I feel like all information I find on the net is outdated about actually setting it up, especially considering that I want to run it with the newest version (0.23.1) and not some old and outdated version.

Do you know any guide, help, instructions or something like that that could help me on the way and give me a good start? :)

Hi, @steemchiller,

I'm here again reaching to you cause im working on some new projects and I would like to ask to you some that I need, is there a way to talk with you? Here is my contact:

Discord: Alejos7ven#2590
Telegram: @Alejos7ven,

Waiting for your word, have a nice day ;)

Hey, we are already friends on Discord, my friend... ^^ I remember accepting your request a while ago. Just send me a message over there and I will reply as soon as possible.

@steemchiller. There seems to be a bug in the steemworld tool of yours. It's taking the post multiple times while calculating the expected payout of my account. Please have a look at the screenshot attached.

sendme.JPG

Thanks for the info! I'm in the process of updating/finishing the whole coming rewards section. The coming beneficiary rewards will also be available in the next few days.

The bug should be fixed now ;)

Sweet. Works great thanks :)

Hey! @steemchiller,

Hope you are doing well, I'm reaching to you to inform that now the Latino Community is running a Witness Node (@cotina)

I'm a dev like you;) always commited to improve my skills and offer the best to the Steem Blockchain.

Thank you, @alejos7ven.

Thank you very much for your efforts.

@tipu curate

Your post is very important for us, we need you and your support.

Coin Marketplace

STEEM 0.27
TRX 0.11
JST 0.030
BTC 67753.90
ETH 3783.00
USDT 1.00
SBD 3.54