GithubHelp home page GithubHelp logo

revelaction / iflandown Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 52 KB

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

License: MIT License

Go 100.00%
raspberry-pi ups ethernet lan golang automation daemon

iflandown's Introduction

iflandown

Go Report Card GitHub Release GitHub Release

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

If your system has a supported version of Go, you can build from source

go install github.com/revelaction/idlandown@latest

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.

iflandown's People

Contributors

revelaction avatar

Stargazers

Michael Demarais avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.