iflandown runs commands after the wired LAN link is down for a given amount of time.

iflandown

iflandown runs commands after the wired LAN link is down for a given amount of time.

All/most linux devices should work. Tested on amd64, Raspberry Pi, odroid

Why

You can use iflandown to avoid filesystem corruption in your rapsberry Pis, when they are connected to an Uninterruptible Power Supply (UPS). iflandown can safely stop the programs running and shutdown the Pi before it runs beyond the UPS time limit, avoiding thus risk of sd card corruption, in case of a too long power outage.

For this to work, the home router shouldn't be protected by the UPS, as it serves as the detection feature.

How it works

iflandown checks each minute the LAN ethernet interfaces in /sys/class/net/%s/carrier to register the state of the link.

If a minimum of uptime minutes Window is not reached inside a defined period of time Period, iflandown executes the configured commands.

Usage

Edit the iflandown.toml file with your preferences:

# The past period of time, starting each minute, that is considered to search
# for at least `Window` minutes of LAN (ethernet) uptime 
#
# It is measured in minutes.
#
# iflandown will also wait this time before starting to make decisions.
# 
# This number of minutes should match roughly the capacity of your UPS to
# serve your devices after a power outage.
Period = 30

# The minimum number of minutes in the `Period` of time that are necessary to
# have been "up" in order to avoid the sequence of commands to run. 
Window = 5

# The commands to run
#
# Separate arguments from the main command and include full paths
# 
# sudo commands are possible
Commands = [["ls", "-alrt"], ["sudo", "/bin/systemctl", "stop", "myservice"]]

And run the command in the same directory as the iflandown.toml file:

iflandown

To run the commands without checks (to test the commands, permissions), run:

iflandown --nocheck

systemd service

There is also a systemd service file to run iflandown as a service. Just change in the file the user name <user>

Run commands as root without passwords

To let iflandown run commands with sudo and no password, add one line in the /etc/sudoers file for each command and arguments that you configured in iflandown.toml.

For example, to let iflandown stop the systemd service myservice, add this line:

    <user> ALL = (root) NOPASSWD: /bin/systemctl stop myservice

Where <user> is the user that will run the iflandown binary/service.

Similar Resources

Simulate network link speed

linkio linkio provides an io.Reader and io.Writer that simulate a network connection of a certain speed, e.g. to simulate a mobile connection. Quick s

Sep 27, 2022

Matterbridge link for Minecraft Server chat.

Matterbridge link for Minecraft Server chat. Simple bridge between Minecraft, Mattermost, IRC, XMPP, Gitter, Slack, Discord, Telegram, Rocket.Chat, Hipchat(via xmpp), Matrix and Steam.

Mar 28, 2022

A tool capable of flashing a D-Link DIR-882 (no IE required!)

A tool capable of flashing a D-Link DIR-882 (no IE required!)

dir882-flasher One problem with the D-Link DIR-882 is that you can only upload firmware using Internet Explorer. IE is going away, and I don't use win

Aug 6, 2022

Undirect - Get redirect link result with golang

Undirect Usage Request http://localhost:5000/?url=https%3A%2F%2Fokjk.co%2FSqOYfk

Jan 12, 2022

link-cheker is a tool to check for broken links.

link-cheker is a tool to check for broken links.

link-checker CLI link-cheker is a tool to check for broken links. By specifying the URL of the page you want to check, you can display a list of broke

Mar 20, 2022

Example of how to write reverse proxy in Go that runs on Cloud Run with Tailscale

Cloudrun Tailscale Reverse Proxy Setup Create a ephemeral key in Tailscale Set TAILSCALE_AUTHKEY in your Cloud Run environment variables Set TARGET_UR

Dec 18, 2022

Keeps track of Steam Deck Verifications. On first run, it reports all games with their respective Steam Deck Verification status. On subsequent runs, the tool will report newly tested and updated games.

Keeps track of Steam Deck Verifications. On first run, it reports all games with their respective Steam Deck Verification status. On subsequent runs, the tool will report newly tested and updated games.

Feb 2, 2022

Ephemeral One Time/Build-Time gRPC TLS PKI system.

PkiSauce Ephemeral Build Time TLS PKI saucing for your intra services GRPC (or not) communications. Description A simple attempt to avoid deploying co

Jul 4, 2022

Given a list of domains, you resolve them and get the IP addresses.

Given a list of domains, you resolve them and get the IP addresses.

resolveDomains Given a list of domains, you resolve them and get the IP addresses. Installation If you want to make modifications locally and compile

Oct 19, 2022
A little web on the LAN
A little web on the LAN

lannet Lannet creates a little web on the LAN. It runs a fileserver daemon in the background, and hosts a homepage that links to other lannet servers

Jan 16, 2022
Connect to SagerNet in the LAN

SagerConnect Connect to SagerNet in the LAN (no configuration required) Usage Upgrade SagerNet to 0.4-rc02 or later Enable "Allow Connections from LAN

Jan 6, 2023
Quickly find all IPv6 and IPv4 hosts in a LAN.

invaentory Quickly find all IPv6 and IPv4 hosts in a LAN. Overview ?? This project is a work-in-progress! Instructions will be added as soon as it is

May 17, 2022
Wake-On-LAN Server for Home Automation
Wake-On-LAN Server for Home Automation

Wake-On-LAN Server for Home Automation This project builds a simple docker container that runs a webserver that allows you to send a wake-on-lan magic

Jan 21, 2022
Wakeonlan - Golang wake on lan service

Wake On Lan Service This application is implemented with golang to wake up the c

Jul 3, 2022
A concurrent map with entries expiring after a specified interval.

go-ttlmap Go TTL Map is a concurent map with entries expiring after a specified interval. This package requires go1.14 or newer. Overview This impleme

Oct 13, 2021
Application to shut down a machine using HTTP requests.

shutdownd Service to shut down a system using HTTP requests. Usage Here's a quick example of how you can use this software on Linux. Download or build

Nov 15, 2021
A wrapper for exposing a shared endpoint for Google Cloud Functions in go. API styled after Node.JS firebase-functions package.

firebase-fx A wrapper for Google Cloud Functions that simplifies the deployment of serverless applications. Meant to expose a similar API to the Fireb

Nov 7, 2022
Anaximander is an ISP probing tool implementing several reduction techniques to cut down the number of probes launched in order to map an Autonomous System
Anaximander is an ISP probing tool implementing several reduction techniques to cut down the number of probes launched in order to map an Autonomous System

Anaximander is an ISP probing tool implementing several reduction techniques to cut down the number of probes launched in order to map an Autonomous System, while still keeping high discovery levels.

Jun 21, 2022
Go-wd - Get the same working directory path at 'go run' and after 'go build'

go-wd Get the same working directory path at 'go run' and after 'go build' Usage

Jan 30, 2022