Coder Social home page Coder Social logo

mrrfv / offline-server-auto-restart Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 43 KB

Use a Raspberry Pi and Tapo P100 (or P105) smart plug to automatically power cycle a server that unexpectedly went down

License: GNU General Public License v3.0

JavaScript 100.00%
failsafe raspberry-pi raspberrypi self-hosted selfhosted server smart-home smart-plug smarthome tapo

offline-server-auto-restart's Introduction

offline-server-auto-restart

Have you tried turning it off and on again? Offline Server Auto Restart uses a Raspberry Pi and Tapo P100 (or P105) smart plug to automatically power cycle a server that unexpectedly went down.

Requirements

  • Tapo P100 or P105 smart plug connected to your server as well as to your network
  • Node.js and npm installed
  • Any open port on the server (could be SSH, HTTP, etc.)
  • Raspberry Pi or similar second computer that is always on and connected to the same network as the smart plug and server

Nice to have

  • BIOS settings configured to turn on the server when power is restored (not absolutely necessary as Wake-on-LAN is used, but it's a good failsafe)

Usage

  1. Clone this repository to your Raspberry Pi
  2. Run npm install to install dependencies
  3. Copy .env.example to .env and fill in the required values
  4. Run node get_device_id.mjs to get the device ID of your smart plug
  5. Copy the device ID to the .env file
  6. Run node index.mjs to start the script. Preferably, use a process manager like PM2 to keep the script running in the background and to automatically restart it if it crashes.

Why not ping?

Some servers respond to ping requests even if they are turned off (for example, devices with Intel AMT configured or servers with Wake-on-LAN enabled). This script checks the ports to see if the server is running.

Important

  • There is a chance that the checked port will be closed during a graceful shutdown or reboot. In that case, the script will assume that the server is down and will power cycle it. This could result in data loss.
  • Servers rebooting into the BIOS or UEFI setup will not be detected as running and will be power cycled.

offline-server-auto-restart's People

Contributors

dependabot[bot] avatar mrrfv avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar

offline-server-auto-restart's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • dotenv ^16.3.1
  • tcp-port-used ^1.0.2
  • tp-link-tapo-connect ^1.0.8
  • webhook-discord ^3.7.8
  • wol ^1.0.7

  • Check this box to trigger a request for Renovate to run again on this repository

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.