Initialize Go module
This commit is contained in:
parent
f9549a10bb
commit
1397fffeca
10 changed files with 1101 additions and 537 deletions
315
README.md
315
README.md
|
|
@ -1,147 +1,234 @@
|
|||

|
||||
# WOL Server - Wake-on-LAN Control Panel for Raspberry Pi
|
||||
|
||||
A lightweight web-based Wake-on-LAN control panel designed for Raspberry Pi that lets you remotely power on and shut down your network devices.
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
|
||||
- **Status Monitoring**: Real-time status checks to determine if your server is online or offline
|
||||
- **Wake-on-LAN**: Boot your server remotely with the click of a button
|
||||
- **Remote Shutdown**: Safely shut down your server when it's not needed
|
||||
- **Responsive UI**: Simple, mobile-friendly interface with color-coded status indicators
|
||||
- **Lightweight**: Built with Go for minimal resource usage, perfect for Raspberry Pi Zero
|
||||
|
||||
## Requirements
|
||||
|
||||
- Raspberry Pi (Zero, 2, 3, 4, etc.)
|
||||
- Go (version 1.16 or higher)
|
||||
- wakeonlan utility
|
||||
- SSH access to the target server (for shutdown functionality)
|
||||
- Target server configured for Wake-on-LAN
|
||||
- **Simple Web Interface**: Boot and shut down your server with a clean, responsive UI
|
||||
- **Status Monitoring**: Check if your target device is online
|
||||
- **Raspberry Pi Optimized**: Built specifically for ARM processors found in all Raspberry Pi models
|
||||
- **Secure Shutdown**: Password-protected shutdown functionality
|
||||
- **Lightweight**: Minimal resource usage ideal for running on even the oldest Pi models
|
||||
- **Easy Setup**: Simple installation process with clear instructions
|
||||
|
||||
## Installation
|
||||
|
||||
### 1. Install Dependencies
|
||||
### Prerequisites
|
||||
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install golang-go wakeonlan
|
||||
```
|
||||
- Raspberry Pi (any model) running Raspberry Pi OS
|
||||
- Network connection
|
||||
- Basic knowledge of SSH/terminal
|
||||
|
||||
### 2. Clone the Repository
|
||||
### Option 1: One-Command Installation
|
||||
|
||||
```bash
|
||||
git clone https://github.com/yourusername/wol-server.git
|
||||
cd wol-server
|
||||
```
|
||||
1. **Download the latest release** on your local machine from the [Releases page](https://github.com/thisloke/wol-server/releases)
|
||||
|
||||
### 3. Configure the Application
|
||||
|
||||
Edit the constants in `main.go` to match your server:
|
||||
|
||||
```go
|
||||
const (
|
||||
serverName = "yourserver" // Hostname or IP address of your server
|
||||
macAddress = "xx:xx:xx:xx:xx:xx" // MAC address of your server's network interface
|
||||
port = "8080" // Port to run the web application on
|
||||
)
|
||||
```
|
||||
|
||||
### 4. Build the Application
|
||||
|
||||
```bash
|
||||
go build -o wol-server
|
||||
```
|
||||
|
||||
### 5. Set Up as a System Service
|
||||
|
||||
Create a systemd service file:
|
||||
|
||||
```bash
|
||||
sudo nano /etc/systemd/system/wol-server.service
|
||||
```
|
||||
|
||||
Add the following content (adjust paths if needed):
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=WOL Server Go Application
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=pi
|
||||
WorkingDirectory=/home/pi/wol-server
|
||||
ExecStart=/home/pi/wol-server/wol-server
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
Enable and start the service:
|
||||
|
||||
```bash
|
||||
sudo systemctl enable wol-server
|
||||
sudo systemctl start wol-server
|
||||
```
|
||||
|
||||
## SSH Configuration for Remote Shutdown
|
||||
|
||||
For the shutdown functionality to work, you need to set up password-less SSH:
|
||||
|
||||
1. Generate an SSH key on your Raspberry Pi:
|
||||
2. **Transfer the package to your Raspberry Pi** using SCP:
|
||||
```bash
|
||||
ssh-keygen -t rsa
|
||||
scp wol-server.tar.gz pi@your-pi-ip:~/
|
||||
```
|
||||
|
||||
2. Copy the key to your target server:
|
||||
3. **SSH into your Raspberry Pi**:
|
||||
```bash
|
||||
ssh-copy-id user@yourserver
|
||||
ssh pi@your-pi-ip
|
||||
```
|
||||
|
||||
3. Configure sudo on the target server to allow password-less shutdown:
|
||||
4. **Install with a single command**:
|
||||
```bash
|
||||
# On the target server, run:
|
||||
sudo visudo
|
||||
|
||||
# Add this line (replacing 'user' with your username):
|
||||
user ALL=(ALL) NOPASSWD: /sbin/shutdown
|
||||
tar -xzf wol-server.tar.gz && ./install.sh
|
||||
```
|
||||
|
||||
5. **Access the web interface** at:
|
||||
```
|
||||
http://your-pi-ip:8080
|
||||
```
|
||||
|
||||
### Option 2: Manual Installation
|
||||
|
||||
If you prefer a manual approach or encounter issues with the automated install:
|
||||
|
||||
1. **Create installation directory**:
|
||||
```bash
|
||||
mkdir -p ~/wol-server/templates
|
||||
```
|
||||
|
||||
2. **Transfer and install program files**:
|
||||
```bash
|
||||
# Copy the executable
|
||||
cp wol-server-arm6 ~/wol-server/wol-server
|
||||
chmod +x ~/wol-server/wol-server
|
||||
|
||||
# Copy template files
|
||||
cp templates/* ~/wol-server/templates/
|
||||
|
||||
# Create .env file
|
||||
cat > ~/wol-server/.env << EOL
|
||||
SERVER_NAME=pippo
|
||||
SERVER_USER=root
|
||||
MAC_ADDRESS=aa:bb:cc:dd:ee:ff
|
||||
PORT=8080
|
||||
EOL
|
||||
```
|
||||
|
||||
3. **Install service**:
|
||||
```bash
|
||||
sudo cp wol-server.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable wol-server
|
||||
sudo systemctl start wol-server
|
||||
```
|
||||
|
||||
4. **Install required dependencies**:
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y wakeonlan sshpass
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
The application can be configured by editing the `.env` file in the installation directory:
|
||||
|
||||
```bash
|
||||
nano ~/wol-server/.env
|
||||
```
|
||||
|
||||
### Available Configuration Options
|
||||
|
||||
| Setting | Description | Default |
|
||||
|---------|-------------|---------|
|
||||
| `SERVER_NAME` | Hostname/IP of target server | pippo |
|
||||
| `SERVER_USER` | SSH username for shutdown | root |
|
||||
| `MAC_ADDRESS` | MAC address for Wake-on-LAN | aa:bb:cc:dd:ee:ff |
|
||||
| `PORT` | Web interface port | 8080 |
|
||||
|
||||
After changing configuration, restart the service:
|
||||
```bash
|
||||
sudo systemctl restart wol-server
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Access the web interface by navigating to `http://raspberry-pi-ip:8080` in your browser.
|
||||
### Accessing the Interface
|
||||
|
||||
The interface provides:
|
||||
Open a web browser and navigate to:
|
||||
```
|
||||
http://your-pi-ip:8080
|
||||
```
|
||||
|
||||
- Current server status (Online/Offline)
|
||||
- Boot button - sends a Wake-on-LAN magic packet to your server
|
||||
- Shutdown button - safely shuts down your server via SSH
|
||||
- Refresh button - manually updates the status display
|
||||
### Features
|
||||
|
||||
- **Status Checking**: The interface shows the current status (Online/Offline)
|
||||
- **Booting**: Click the "Boot" button to send a WOL magic packet
|
||||
- **Shutting Down**: Click "Shutdown" and enter your SSH password when prompted
|
||||
|
||||
## Maintenance
|
||||
|
||||
### Checking Service Status
|
||||
|
||||
```bash
|
||||
sudo systemctl status wol-server
|
||||
```
|
||||
|
||||
### Viewing Logs
|
||||
|
||||
```bash
|
||||
sudo journalctl -u wol-server -f
|
||||
```
|
||||
|
||||
### Updating
|
||||
|
||||
To update to a newer version:
|
||||
|
||||
1. Download and transfer the latest release
|
||||
2. Stop the service:
|
||||
```bash
|
||||
sudo systemctl stop wol-server
|
||||
```
|
||||
3. Extract the new files:
|
||||
```bash
|
||||
tar -xzf wol-server.tar.gz
|
||||
```
|
||||
4. Run the install script:
|
||||
```bash
|
||||
./install.sh
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- **Server won't boot**:
|
||||
- Verify that Wake-on-LAN is enabled in your server's BIOS/UEFI
|
||||
- Confirm the MAC address is correct
|
||||
- Check if your router blocks Wake-on-LAN packets
|
||||
### Service Won't Start
|
||||
|
||||
- **Shutdown doesn't work**:
|
||||
- Verify SSH key setup
|
||||
- Check sudo configuration on target server
|
||||
- Test manual SSH command: `ssh user@server sudo shutdown -h now`
|
||||
Check for template errors:
|
||||
```bash
|
||||
ls -la ~/wol-server/templates/
|
||||
```
|
||||
|
||||
- **Web interface not accessible**:
|
||||
- Ensure the service is running: `sudo systemctl status wol-server`
|
||||
- Check for firewall rules blocking port 8080
|
||||
- Verify the Raspberry Pi is connected to the network
|
||||
Verify the .env file exists:
|
||||
```bash
|
||||
cat ~/wol-server/.env
|
||||
```
|
||||
|
||||
## Contributing
|
||||
### Boot Command Not Working
|
||||
|
||||
Contributions are welcome! Please feel free to submit a Pull Request.
|
||||
1. Ensure `wakeonlan` is installed:
|
||||
```bash
|
||||
which wakeonlan || sudo apt-get install wakeonlan
|
||||
```
|
||||
2. Verify the MAC address is correct in your .env file
|
||||
3. Make sure the target device is properly configured for Wake-on-LAN
|
||||
|
||||
## License
|
||||
### Shutdown Not Working
|
||||
|
||||
1. Verify `sshpass` is installed:
|
||||
```bash
|
||||
which sshpass || sudo apt-get install sshpass
|
||||
```
|
||||
2. Check that the SERVER_USER setting in .env is correct
|
||||
3. Ensure SSH access is working between your Pi and the target server
|
||||
|
||||
## Advanced Configuration
|
||||
|
||||
### Running on a Different Port
|
||||
|
||||
Edit the `.env` file:
|
||||
```bash
|
||||
echo "PORT=8181" >> ~/wol-server/.env
|
||||
```
|
||||
|
||||
### Multiple Target Machines
|
||||
|
||||
To control multiple devices, you can install multiple instances:
|
||||
```bash
|
||||
# Create a second instance
|
||||
mkdir -p ~/wol-server2/templates
|
||||
cp -r ~/wol-server/templates/* ~/wol-server2/templates/
|
||||
cp ~/wol-server/wol-server ~/wol-server2/
|
||||
|
||||
# Different config
|
||||
cat > ~/wol-server2/.env << EOL
|
||||
SERVER_NAME=server2
|
||||
SERVER_USER=admin
|
||||
MAC_ADDRESS=aa:bb:cc:dd:ee:ff
|
||||
PORT=8081
|
||||
EOL
|
||||
|
||||
# Create a new service
|
||||
sudo cp /etc/systemd/system/wol-server.service /etc/systemd/system/wol-server2.service
|
||||
sudo sed -i 's|/home/pi/wol-server|/home/pi/wol-server2|g' /etc/systemd/system/wol-server2.service
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable wol-server2
|
||||
sudo systemctl start wol-server2
|
||||
```
|
||||
|
||||
## Project Information
|
||||
|
||||
Designed for use with Raspberry Pi to provide a simple way to manage servers and devices on your local network. The web interface makes it easy to power on and off machines without having to remember MAC addresses or commands.
|
||||
|
||||
### Contributing
|
||||
|
||||
Contributions are welcome! Feel free to submit pull requests or open issues to help improve this project.
|
||||
|
||||
### License
|
||||
|
||||
This project is licensed under the MIT License - see the LICENSE file for details.
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
- Inspired by the need for a simple, lightweight server power management tool
|
||||
- Thanks to the Go community for the excellent standard library that makes web development straightforward
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue