Skip to content

Instantly share code, notes, and snippets.

View mharsch's full-sized avatar

Mike Harsch mharsch

View GitHub Profile
@mharsch
mharsch / hostname_watchdog.md
Last active June 16, 2023 21:37
setup linux to reboot if the host loses access to hostname (not IP)

Deprecated

I no longer recommend the below method. For my updated recommendation, see this gist

Setup Linux to reboot if it loses access to a certain host by hostname (not IP)

The linux watchdog service can be configured to run certain 'liveness' tests periodically, and then take some action (such as reboot) if a test fails (and doesn't recover) for some period of time.

There is a built-in test for pinging an IP address (i.e. 'ping' directive), but you may instead need to test access to a hostname

@mharsch
mharsch / gist:fc04ef0d236ebb66965e1a0d0232ece9
Last active May 13, 2022 18:09
user watchdog script for flooding system log errors
If you have a failure mode that can be diagnosed by a high rate of messages flooding the system log,
you can use the script below in conjunction with the watchdog service to detect the condition
and reboot if it persists. This is a pretty big hammer, but potentially better than just rebooting on
loss of network or some other arbitrary liveness test.
add a 'test-binary' line to /etc/watchdog.conf pointing to this script (will be treated as V0 test script
with no corresponding repair script). Also, set 'interval' to something like 20 seconds (at least greater than
the sample period in the script).
You can convince yourself it's working (once the watchdog service has been restarted with the above config)
@mharsch
mharsch / gist:b1108372982a1921235563ee5f603807
Last active December 30, 2023 16:38
run a service on a schedule (e.g. off-peak electricity rates)
We want to run a long-running process during certain hours, days-of-the-week, etc.
We want the service to start on a schedule, and be stopped on a corresponding schedule.
Example: Residential electric rates are based on Time of Use (TOU) such that Weekdays
from 1p to 7p are considered 'Peak Hours' when rates are much higher than all other times.
Our long running process uses significant electricity, so we want to stop running it
once we reach the Peak Hours period, and resume running once the Peak period is over.
1.) We create a systemd service file for the long running process (foo.service)
2.) We create a systemd timer unit associated with the service (foo.timer). This timer handles
Task: add vector type option parsing to chia_plot for the -t and -2 options
so the user can specify a comma-separated list of paths instead of just a single path
e.g.
./chia-plot -n 4 -t /mnt/ssd1/,/mnt/ssd2 -2 /mnt/ssd3/,/mnt/ssd4/,/mnt/ssd5 <other options>
in the above example the actual paths used will be as follows:
plot -t_path -2_path
@mharsch
mharsch / gist:424adca0e264a79493b8e5a02096be1d
Created March 5, 2021 18:23
EM1000T-VZ-CAT1 on Raspberry Pi using ModemManager 1.14
The version of ModemManager that ships with Raspberry Pi OS (1.10) doesn't appear to work with the Telit LE910 V2
in MBIM mode (AT#USBCFG=3) and so we must upgrade to a newer version (1.14). Thankfully, that is available via
the debian backports repository.
0.) Add this line to /etc/apt/sources.list
deb http://deb.debian.org/debian buster-backports main
1.) Download and install the Debian repo key package
wget http://deb.debian.org/debian/pool/main/d/debian-archive-keyring/debian-archive-keyring_2021.1.1_all.deb
sudo dpkg -i debian-archive-keyring_2021.1.1_all.deb
@mharsch
mharsch / gist:3e855c192c75767f7c220abbf6d66404
Created February 22, 2021 18:42
ConnectedIO EM1000T-VZ-CAT1 modem on Raspberry Pi
How to setup the Raspberry Pi to use the Connected IO EM1000T-VZ-CAT1 modem in MBIM mode
(Tested on Pi 4 model B (2GB), Raspberry Pi OS Buster 2021-01-11 release, Modem firmwre 20.00.015)
First put the modem into MBIM mode by issuing the following AT command (using minicom -D /dev/ttyACM0)
at#usbcfg=5
Power off /on modem, reboot Pi
Confirm the following device exists
/dev/cdc-wdm0
@mharsch
mharsch / gist:981ce81429e9012bb0efd0149f7556fd
Last active February 6, 2021 15:55
Get ethereum mining working on Ubuntu + NVIDIA Docker host
Make sure the host has up-to-date nvidia drivers (460 as of this writing)
sudo apt install nvidia-headless-460
Download ethminer to current directory:
wget https://github.com/ethereum-mining/ethminer/releases/download/v0.19.0-alpha.0/ethminer-0.19.0-alpha.0-cuda-9-linux-x86_64.tar.gz
Create Dockerfile as follows:
FROM nvidia/cuda:11.2.0-base-ubuntu18.04
LABEL description="ethminer container for NVIDIA GPU systems"
@mharsch
mharsch / gist:cfd02f95d8ae784c638f465251b9dcbb
Created January 25, 2021 22:05
why does this fail in the Node-RED function editor?
if (msg.payload == 0) {
msg.payload = "No trip factor "
} else if (msg.payload == 1) {
msg.payload = "Over-current event while at constant speed"
} else if (msg.payload == 2) {
msg.payload = "Over-current event during deceleration"
} else if (msg.payload == 3) {
msg.payload = "Over-current event during acceleration "
} else if (msg.payload == 4) {
msg.payload = "Over-current event during other conditions"
@mharsch
mharsch / gist:f2bb226caa1de91abaa95f28c6d17b7b
Created January 24, 2021 16:48
ethminer on ROCm Dockerfile
FROM ubuntu:18.04
LABEL description="ethminer AMD ROCm Container"
ENV API_PORT=3333
COPY ethminer.tar.gz ./ethminer.tar.gz
ARG ROCM_VER=4.0.0
RUN apt-get update \
@mharsch
mharsch / gist:942811d575987d6589886a09ad9e754b
Created January 24, 2021 16:43
build ethminer on ROCm host
cd ethminer
mkdir build
cd build
cmake .. -DETHASHCUDA=OFF -DETHASHCL=ON -DUSE_SYS_OPENCL=ON -DAPICORE=ON
CPATH=/opt/rocm/opencl/include cmake --build .