https://github.com/revelaction/iflandown
iflandown is a deamon tha truns commands after the wired LAN link is down for a given amount of time.
https://github.com/revelaction/iflandown
automation daemon ethernet golang lan raspberry-pi ups
Last synced: 4 months ago
JSON representation
iflandown is a deamon tha truns commands after the wired LAN link is down for a given amount of time.
- Host: GitHub
- URL: https://github.com/revelaction/iflandown
- Owner: revelaction
- License: mit
- Created: 2022-03-02T09:22:59.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-11T14:16:43.000Z (over 1 year ago)
- Last Synced: 2025-01-20T16:32:30.897Z (about 1 year ago)
- Topics: automation, daemon, ethernet, golang, lan, raspberry-pi, ups
- Language: Go
- Homepage:
- Size: 55.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://goreportcard.com/report/github.com/revelaction/iflandown)
[]()
[]()
`iflandown` is a deamon that monitors the LAN link and runs commands if it 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.
# Installation
On Linux, macOS, and FreeBSD and Windows you can use the [pre-built binaries](https://github.com/revelaction/iflandown/releases/)
If your system has a supported version of Go, you can build from source
```console
go install github.com/revelaction/idlandown@latest
```
## Usage
Edit the `iflandown.toml` file with your preferences:
```toml
# 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:
```console
iflandown
```
To run the commands without checks (to test the commands, permissions), run:
```console
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 ``
## 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:
```
ALL = (root) NOPASSWD: /bin/systemctl stop myservice
```
Where `` is the user that will run the `iflandown` binary/service.