feat: Add Dockerfile, README.md, docker-compose.yml and update index.html
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
# Server Management Tool
|
||||
|
||||
This is a simple Go application designed to manage your servers, providing functionalities to list, wake up (Wake-on-LAN), shut down, and reboot them. It offers both a command-line interface (CLI) and a web-based interface for convenient management.
|
||||
|
||||
## Features
|
||||
|
||||
* **List Servers:** Display all configured servers with their details.
|
||||
* **Wake Server:** Send Wake-on-LAN (WoL) magic packets to bring servers online.
|
||||
* **Shutdown Server:** Remotely shut down servers via SSH.
|
||||
* **Reboot Server:** Remotely reboot servers via SSH.
|
||||
* **Server Status:** Check if servers are online using ping.
|
||||
* **Web Interface:** A user-friendly web interface to perform all management actions.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before you begin, ensure you have the following installed:
|
||||
|
||||
* [Go (1.24.6 or newer)](https://golang.org/doc/install)
|
||||
* [Docker](https://docs.docker.com/get-docker/)
|
||||
* `git` (for cloning the repository)
|
||||
|
||||
## Getting Started (Local)
|
||||
|
||||
1. **Clone the repository:**
|
||||
|
||||
```bash
|
||||
git clone git@git.hnrx.net:hnrx/manage-servers.git
|
||||
cd manage-servers
|
||||
```
|
||||
|
||||
2. **Configure your servers:**
|
||||
|
||||
Edit the `servers.json` file to include your server details, including MAC addresses for Wake-on-LAN and SSH credentials for shutdown/reboot.
|
||||
|
||||
Example `servers.json`:
|
||||
```json
|
||||
[
|
||||
{
|
||||
"name": "harvester-01",
|
||||
"mac": "3c:49:37:05:c2:2e",
|
||||
"ip": "192.168.110.101",
|
||||
"ssh_user": "rancher",
|
||||
"ssh_pass": "maddog07"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
3. **Run CLI commands:**
|
||||
|
||||
```bash
|
||||
go run . list
|
||||
go run . wake harvester-01
|
||||
go run . status
|
||||
go run . shutdown harvester-01
|
||||
go run . reboot harvester-01
|
||||
```
|
||||
|
||||
4. **Run the web server locally:**
|
||||
|
||||
```bash
|
||||
go run . serve
|
||||
```
|
||||
|
||||
Access the web interface in your browser at `http://localhost:8080`.
|
||||
|
||||
## Getting Started (Docker)
|
||||
|
||||
1. **Build the Docker image:**
|
||||
|
||||
Navigate to the root of the project and run:
|
||||
|
||||
```bash
|
||||
docker build -t manage-servers:latest .
|
||||
```
|
||||
|
||||
2. **Run the Docker container:**
|
||||
|
||||
To enable Wake-on-LAN functionality, the Docker container needs to run in `host` network mode. This allows it to send broadcast packets directly onto your physical network.
|
||||
|
||||
```bash
|
||||
docker run --network host -p 8080:8080 manage-servers:latest
|
||||
```
|
||||
|
||||
* `--network host`: Essential for Wake-on-LAN to work correctly.
|
||||
* `-p 8080:8080`: Maps port 8080 from the container to port 8080 on your host.
|
||||
|
||||
3. **Access the web interface:**
|
||||
|
||||
Open your web browser and navigate to `http://localhost:8080`.
|
||||
|
||||
## Configuration
|
||||
|
||||
The `servers.json` file is crucial for the application's functionality. Ensure it's correctly formatted and contains accurate information for all your servers.
|
||||
|
||||
* `name`: A unique identifier for your server.
|
||||
* `mac`: The MAC address of the server for Wake-on-LAN.
|
||||
* `ip`: The IP address of the server for SSH connections and status checks.
|
||||
* `ssh_user`: The username for SSH access.
|
||||
* `ssh_pass`: The password for SSH access.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Host key verification failed (when pushing to Git)
|
||||
|
||||
If you encounter `Host key verification failed` when pushing to your Git repository, it means your system does not trust the SSH key of the Git server. To resolve this, you need to manually add the server's host key to your `~/.ssh/known_hosts` file.
|
||||
|
||||
From your terminal, attempt to connect to the server via SSH for the first time:
|
||||
|
||||
```bash
|
||||
ssh git@192.168.200.20
|
||||
```
|
||||
|
||||
When prompted to confirm the host's authenticity, type `yes` and press Enter. This will add the host key to your `known_hosts` file, and you should then be able to push your changes.
|
||||
|
||||
### Error loading servers: open servers.json: no such file or directory (in Docker)
|
||||
|
||||
This error indicates that the `servers.json` file was not found inside the Docker container. Ensure you have the latest `Dockerfile` (which includes copying `servers.json`) and rebuild your Docker image.
|
||||
|
||||
### Sending magic packet from Docker container does not work
|
||||
|
||||
If Wake-on-LAN is not working from within the Docker container, it's likely a networking issue. Ensure you are running the Docker container with the `--network host` flag, as described in the "Run the Docker container" section above. This allows the container to send broadcast packets directly onto your physical network.
|
||||
Reference in New Issue
Block a user