NVME Drive Keep Alive Script

Placed in /Scripts/keepalive

 pi@raspberry01:~/Scripts/keepalive$ cat keepalive.sh 
 #bin/bash
 
## BAINWERX
## NVME Keepalive Read|Write Script
## version 1.2
## created Feb 2021

## Time in 12 hr format
 logging_time=$(date +'%r')
 
## backup dir format
 logging_dir=$(date +'%m_%d_%Y')
 
find /home/pi/Scripts/keepalive/*.log -mtime 1 -delete;
 echo "NVME Keepalive Read|Write at" "${logging_time}" >> /home/pi/Scripts/keepalive/"${logging_dir}".log 

Runing this script will create a .log file with a simple write to the nvme drive. Next step wil be to setup a cron task with

sudo crontab -e

add the following lines to enable the script

# nvme drive keepalive by posting to drive every minute
 */1 * * * * sudo sh /home/pi/Scripts/keepalive/keepalive.sh

Now Save and reboot the system.

NOTE

If you are adding this with pihole…you might want to add the following step which will run when the pi is rebooted. It tells the pi that when it reboots…wait 15 seconds and then restart the pihole dns resolution

# On reboot + 15 seconds restart the pihole dns resolver (loop prevention)
 
@reboot sleep 15 && sudo pihole restartdns

Cluster Management with Ansible

Now that I have my “base cluster” up and running with ProxMox, it’s time to turn my attention to how I’m going to manage it.

After creating a new management user I setup ssh certs to permit ssh traffic from the master to slave systems.

Instalation of Ansible was a breeze

$ sudo apt update
$ sudo apt install software-properties-common
$ sudo apt-add-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible

After creating an inventory file, and then a quick and dirty playboook...I tested it out and...

voila!

First run went smashing..although it showed that there WAS actually an update or two on 2/3 of the servers.

After running my playbook again it looks like everything was in fact in order.

Ubuntu 20.10 Server Virtualization Challenges

===============================================================

Issue #1 – IP Address not configured correctly

The fix

sudo rm /etc/machine-id
sudo systemd-machine-id-setup
sudo reboot

as per https://jaylacroix.com/fixing-ubuntu-18-04-virtual-machines-that-fight-over-the-same-ip-address/

===============================================================

Issue #2 – Time Sync (aka NTP Server / Client Config)

The fix

setup ntp server on ubuntu01

setup ntp client on ubuntu02 through ubuntu04

as per https://vitux.com/how-to-install-ntp-server-and-client-on-ubuntu/

===============================================================

Issue #3 – Time / Date Appearance

The fix – simple reconfiguration as per https://linuxize.com/post/how-to-set-or-change-timezone-on-ubuntu-18-04/

Raspbian Commands – RFKILL

RFKILL is a handy tool to hard disable wireless and bluetooth from Raspbian devices like a pi. Unlike other command line tools, this is persistant meaning that it will survive reboots until it is unblocked.

sudo rfkill block wifi
sudo rfkill block bluetooth

to undo…

sudo rfkill unblock wifi
sudo rfkill unblock bluetooth

Amazon Alexa – Announce Feature (How to exclude a device from an announcement)

This took a few minutes to figure out.

Basically you are making a standard timed announcement…but FIRST you need to set the Do Not Disturb flag to the Amazon Echo device (or devices) that you want to ignore.

In this example, I want to set up a bedtime alert for each kid. Before 10pm it’s perfectly fine to make an announcement on every device, but once 10pm rolls around, I want to make sure that my wife’s sleep isn’t disrupted in the bedroom. This means removing our Echo from the Announce listing…except that it’s not really an option.

So first, I set the Do Not Disturb flag for the Amazon FireStick TV and Amazon Echo that are in the master bedroom for a duration of 1 minute.

Then I have it play the required announcement. Confirmed, nothing plays in the master bedroom for 1 minute.

Once the 1 minute is up…I can send any required notifications to all devices as normal.

Raspberry PI – Wireless Scanning

We stepped up to a wireless mesh network at the house this weekend. We’ve been having a lot of weird wireless issues in the last week or so…so we updated our old Linksys routers to a new wireless mesh.

Switching wireless id’s wasn’t the end of the world…I thought it would be a bigger pain in the butt…but it’s really not that terrible. Most applications have a method to be able to switch the wireless network they connect to “fairly painlessly”. Even the Ring doorbell (which has 2 extra steps) wasn’t terrible.

I did want to try and figure out how to wirelessly scan and confirm which networks the pi’s were on as they serve a couple of purposes for us.

wgetid will show you the network the pi is connected to.

sudo iwlist wlan0 scan | egrep “Cell|ESSID|Signal|Rates” will provide a quick wireless scan and show you the strength and rates available.

Home Automation

Earlier this year I bought a couple of Alexa Echo Flex units to play with.

The idea was to get an idea of how home automation is finally starting to evolve.

The notion of home automation isn’t new, but with the evolution of wireless technologies, and the ever evolving world of personal assistants and home tools….well…it get’s very interesting indeed.

It was the Amazon Alexa Flex units that actually really intrigued me. They are smaller units that plug directly into a wall outlet, and as a result they blend directly into the background very quickly and easily. Due to their smaller size the sound quality that comes out is okay for voice command and acknowledgements…but not great for music.

BUT

They do have the option to connect to bluetooth speakers…which changes things drastically.

Next I purchased a pair of Teckin outlets from Amazon. They use the SmartLife application which is pretty alright, and works as an interpreter between the outlet devices and Alexa.

Basically…you tell Alexa what you want and it looks to see what it’s connected to in order to accomplish the demand. I created a group called Living room and Fireplace room and was able to use voice command to turn the lights on and off.

You can get very complex using the SmartLife app…it’s a very interesting tool.

The next add was an Amazon Echo…a bigger unit with much better sound, as well as a pair of Teckin wireless LED lights. So now I can go to bed…say goodnight and all of the lights in the house will turn off…I can even have Alexa arm my security system…

Pretty slick.

Raspberry Pi – Mounting an NFS @ boot

I have an “every 3rd night backup” script that’s been crashing out, and it’s because as soon as I log off the system drops the file share…so the system forgets where to store backups.

So using the logic of the following crontab that works I’ve made my own slightly customized version…

@reboot sleep 30 && python /path/to/your/script.py &

Reverse engineering the code, the secret sauce is actually in the sleep 30, which is basically telling the system to wait for a few ticks before running the following command…which ironically waits just long enough for the network stack to be fully up and running and then mount.

@reboot sleep 30 && sudo mount -t nfs 192.168.1.8:/volume1/pi /media/SYNOLOGY