Battery Status Monitor: Keep Your Linux Server Safe from Power Failures When Serving Laptop As A Server

Battery Status Monitor: Keep Your Linux Server Safe from Power Failures

As more people convert old laptops into home servers, managing battery life becomes crucial. Today, I'm excited to share  project that solves this exact problem: a web-based Battery Status Monitor with automatic shutdown capabilities for Linux systems.




Source Code on Github



Who Should Use This?

  • Home lab enthusiasts running servers on laptops
  • Developers using laptop-based development servers
  • Anyone running Linux services on battery-powered devices

Why You Need This

Imagine your laptop-server running critical services suddenly dies due to battery drain. Not good, right? This tool helps by:

  1. Providing real-time battery monitoring through a web interface
  2. Automatically scheduling safe shutdowns when battery is low
  3. Preventing data loss from unexpected power-offs
  4. Offering remote monitoring capabilities

Key Features

1. Web-Based Monitoring

  • Clean, modern interface showing battery percentage, charging status, and detailed metrics
  • Accessible from any device on your network
  • Auto-refreshing status updates every 30 seconds

2. Smart Power Management

  • Monitors battery status every 5 minutes
  • Automatically schedules shutdown when battery drops below 20%
  • Cancels scheduled shutdowns if power is restored
  • Detailed logging of all actions

3. Easy Integration

  • RESTful API endpoint for system integration
  • Simple setup process
  • Runs as a system service
  • Minimal resource usage

When to Use

  • Running home automation servers on old laptops
  • Development environments on portable machines
  • Temporary server setups with unreliable power
  • Backup systems that need graceful shutdown

Technical Benefits

1. Resource Efficient

  • Written in Python using Tornado framework
  • Minimal CPU and memory footprint
  • Non-blocking asynchronous operations

2. Security Focused

  • Runs on localhost by default
  • CORS enabled for API access
  • Supports reverse proxy setups

3. Reliability

  • Continuous monitoring and logging
  • Automatic recovery from errors
  • Failsafe shutdown mechanisms

Getting Started


git clone https://github.com/01one/battery-status-on-linux-laptop-as-a-server.git
cd battery-status-on-linux-laptop-as-a-server
pip install -r requirements.txt
sudo python3 app.py

Pro Tips

  1. System Service Setup
    • Configure as a systemd service for automatic startup
    • Enable log rotation for long-term use
  2. Remote Access
    • Use Nginx as a reverse proxy
    • Set up Cloudflare Tunnel for secure remote access
    • Enable HTTPS for security
  3. Customization
    • Adjust threshold values for your needs
    • Modify shutdown delay timing
    • Customize the web interface

Real-World Applications

1. Home Lab Scenarios

  • Running Server From a laptop
  • Home media servers
  • Development environments

2. Small Office Setups

  • Backup servers
  • Testing environments
  • Temporary deployments

This Battery Status Monitor fills a crucial gap in laptop-based server setups. It's a must-have tool for anyone running Linux services on battery-powered devices. The combination of web interface, automatic shutdown, and easy setup makes it an invaluable addition to your server management toolkit.

Remember: Prevention is better than cure. Don't wait for a battery-related disaster to implement proper power management for your servers.

Feel free to contribute to the project on GitHub or share your experiences