mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 01:39:34 +08:00
Merge branch 'delta-whiplash-main'
This commit is contained in:
13
readme.md
13
readme.md
@@ -61,6 +61,9 @@ If you don't need network stats, remove that line from the compose file and map
|
||||
|
||||
### Binary
|
||||
|
||||
> [!TIP]
|
||||
> If using Linux, see [guides/systemd.md](/supplemental/guides/systemd.md) for a script to install the hub or agent as a system service. The agent installer will be built into the web UI in the future.
|
||||
|
||||
Download and run the latest binaries from the [releases page](https://github.com/henrygd/beszel/releases) or use the commands below.
|
||||
|
||||
#### Hub
|
||||
@@ -87,18 +90,10 @@ Running the agent directly:
|
||||
PORT=45876 KEY="{PASTE_YOUR_KEY}" ./beszel-agent
|
||||
```
|
||||
|
||||
#### Running as a system service (Linux)
|
||||
|
||||
See [supplemental/systemd](/supplemental/systemd) for instructions on running in the background using systemd.
|
||||
|
||||
In the future there will be a one line command for installing the binary and setting up the service.
|
||||
|
||||
#### Updating
|
||||
|
||||
Use `./beszel update` and `./beszel-agent update` to update to the latest version.
|
||||
|
||||
If using systemd, run `sudo systemctl restart beszel` and `sudo systemctl restart beszel-agent` to restart the services.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
### Hub
|
||||
@@ -196,7 +191,7 @@ Connectivity can be tested by running `telnet <agent-ip> <port>`.
|
||||
|
||||
### Connecting the hub and agent on the same system using Docker
|
||||
|
||||
If using host network mode for the agent but not the hub, you can add your system using the hostname `host.docker.internal`, which resolves to the internal IP address used by the host. See [example docker-compose.yml](/supplemental/docker/examples/same-system/docker-compose.yml).
|
||||
If using host network mode for the agent but not the hub, you can add your system using the hostname `host.docker.internal`, which resolves to the internal IP address used by the host. See [example docker-compose.yml](/supplemental/docker/same-system/docker-compose.yml).
|
||||
|
||||
If using host network for both, you can use `localhost` as the hostname.
|
||||
|
||||
|
125
supplemental/guides/systemd.md
Normal file
125
supplemental/guides/systemd.md
Normal file
@@ -0,0 +1,125 @@
|
||||
# Installing as a Linux systemd service
|
||||
|
||||
This is useful if you want to run the hub or agent in the background continuously, including after a reboot.
|
||||
|
||||
## Install script (recommended)
|
||||
|
||||
There are two scripts, one for the hub and one for the agent. You can run either one, or both.
|
||||
|
||||
The install script creates a dedicated user for the service (`beszel`), downloads the latest release, and installs the service.
|
||||
|
||||
> [!NOTE]
|
||||
> You need system administrator privileges to run the install script. If you encounter a problem, please [open an issue](https://github.com/henrygd/beszel/issues/new).
|
||||
|
||||
### Hub
|
||||
|
||||
Download the script:
|
||||
|
||||
```bash
|
||||
curl -sL https://raw.githubusercontent.com/henrygd/beszel/main/supplemental/scripts/install-hub.sh -o install-hub.sh && chmod +x install-hub.sh
|
||||
```
|
||||
|
||||
#### Install
|
||||
|
||||
```bash
|
||||
./install-hub.sh
|
||||
```
|
||||
|
||||
#### Uninstall
|
||||
|
||||
```bash
|
||||
./install-hub.sh -u
|
||||
```
|
||||
|
||||
#### Update
|
||||
|
||||
```bash
|
||||
sudo /opt/beszel/beszel update && sudo systemctl restart beszel
|
||||
```
|
||||
|
||||
### Agent
|
||||
|
||||
Download the script:
|
||||
|
||||
```bash
|
||||
curl -sL https://raw.githubusercontent.com/henrygd/beszel/main/supplemental/scripts/install-agent.sh -o install-agent.sh && chmod +x install-agent.sh
|
||||
```
|
||||
|
||||
#### Install
|
||||
|
||||
You may optionally include the SSH key and port as arguments. Run `./install-agent.sh -h` for more info.
|
||||
|
||||
```bash
|
||||
./install-agent.sh
|
||||
```
|
||||
|
||||
#### Uninstall
|
||||
|
||||
```bash
|
||||
./install-agent.sh -u
|
||||
```
|
||||
|
||||
#### Update
|
||||
|
||||
```bash
|
||||
sudo /opt/beszel-agent/beszel-agent update && sudo systemctl restart beszel-agent
|
||||
```
|
||||
|
||||
## Manual install
|
||||
|
||||
1. Create the system service at `/etc/systemd/system/beszel.service`
|
||||
|
||||
```bash
|
||||
[Unit]
|
||||
Description=Beszel Hub Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
# update the values in the curly braces below (remove the braces)
|
||||
ExecStart={/path/to/working/directory}/beszel serve
|
||||
WorkingDirectory={/path/to/working/directory}
|
||||
User={YOUR_USERNAME}
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
2. Start and enable the service to let it run after system boot
|
||||
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable beszel.service
|
||||
sudo systemctl start beszel.service
|
||||
```
|
||||
|
||||
## Run the agent as a system service (Linux)
|
||||
|
||||
This runs the agent in the background continuously using systemd.
|
||||
|
||||
1. Create the system service at `/etc/systemd/system/beszel-agent.service`
|
||||
|
||||
```bash
|
||||
[Unit]
|
||||
Description=Beszel Agent Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
# update the values in curly braces below (remove the braces)
|
||||
Environment="PORT={PASTE_YOUR_PORT_HERE}"
|
||||
Environment="KEY={PASTE_YOUR_KEY_HERE}"
|
||||
ExecStart={/path/to/directory}/beszel-agent
|
||||
User={YOUR_USERNAME}
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
2. Start and enable the service to let it run after system boot
|
||||
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable beszel-agent.service
|
||||
sudo systemctl start beszel-agent.service
|
||||
```
|
132
supplemental/scripts/install-agent.sh
Executable file
132
supplemental/scripts/install-agent.sh
Executable file
@@ -0,0 +1,132 @@
|
||||
#!/bin/bash
|
||||
version=0.0.1
|
||||
# Define default values
|
||||
PORT=45876
|
||||
|
||||
# Read command line options
|
||||
while getopts ":k:p:uh" opt; do
|
||||
case $opt in
|
||||
k) KEY="$OPTARG";;
|
||||
p) PORT="$OPTARG";;
|
||||
u) UNINSTALL="true";;
|
||||
h) printf "Beszel Agent installation script\n\n"
|
||||
printf "Usage: ./install-agent.sh [options]\n\n"
|
||||
printf "Options: \n"
|
||||
printf " -k : SSH key (required, or interactive if not provided)\n"
|
||||
printf " -p : Port (default: $PORT)\n"
|
||||
printf " -u : Uninstall the Beszel Agent\n"
|
||||
printf " -h : Display this help message\n"
|
||||
exit 0;;
|
||||
\?) echo "Invalid option: -$OPTARG"; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$UNINSTALL" = "true" ]; then
|
||||
# Stop and disable the Beszel Agent service
|
||||
echo "Stopping and disabling the Beszel Agent service..."
|
||||
sudo systemctl stop beszel-agent.service
|
||||
sudo systemctl disable beszel-agent.service
|
||||
|
||||
# Remove the systemd service file
|
||||
echo "Removing the systemd service file..."
|
||||
sudo rm /etc/systemd/system/beszel-agent.service
|
||||
|
||||
# Reload the systemd daemon
|
||||
echo "Reloading the systemd daemon..."
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
# Remove the Beszel Agent directory
|
||||
echo "Removing the Beszel Agent directory..."
|
||||
sudo rm -rf /opt/beszel-agent
|
||||
|
||||
# Remove the dedicated user for the Beszel Agent service
|
||||
echo "Removing the dedicated user for the Beszel Agent service..."
|
||||
sudo userdel beszel
|
||||
|
||||
echo "The Beszel Agent has been uninstalled successfully!"
|
||||
else
|
||||
# Function to check if a package is installed
|
||||
package_installed() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Check for package manager and install necessary packages if not installed
|
||||
if package_installed apt-get; then
|
||||
if ! package_installed tar || ! package_installed curl; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y tar curl
|
||||
fi
|
||||
elif package_installed yum; then
|
||||
if ! package_installed tar || ! package_installed curl; then
|
||||
sudo yum install -y tar curl
|
||||
fi
|
||||
elif package_installed pacman; then
|
||||
if ! package_installed tar || ! package_installed curl; then
|
||||
sudo pacman -Sy --noconfirm tar curl
|
||||
fi
|
||||
else
|
||||
echo "Warning: Please ensure 'tar' and 'curl' are installed."
|
||||
fi
|
||||
|
||||
# If no SSH key is provided, ask for the SSH key interactively
|
||||
if [ -z "$KEY" ]; then
|
||||
read -p "Enter your SSH key: " KEY
|
||||
fi
|
||||
|
||||
# Create a dedicated user for the service if it doesn't exist
|
||||
if ! id -u beszel > /dev/null 2>&1; then
|
||||
echo "Creating a dedicated user for the Beszel Agent service..."
|
||||
sudo useradd -M -s /bin/false beszel
|
||||
fi
|
||||
|
||||
# Create the directory for the Beszel Agent
|
||||
if [ ! -d "/opt/beszel-agent" ]; then
|
||||
echo "Creating the directory for the Beszel Agent..."
|
||||
sudo mkdir -p /opt/beszel-agent
|
||||
sudo chown beszel:beszel /opt/beszel-agent
|
||||
sudo chmod 755 /opt/beszel-agent
|
||||
fi
|
||||
|
||||
# Download and install the Beszel Agent
|
||||
echo "Downloading and installing the Beszel Agent..."
|
||||
curl -sL "https://github.com/henrygd/beszel/releases/latest/download/beszel-agent_$(uname -s)_$(uname -m | sed 's/x86_64/amd64/' | sed 's/armv7l/arm/' | sed 's/aarch64/arm64/').tar.gz" | tar -xz -O beszel-agent | tee ./beszel-agent >/dev/null
|
||||
sudo mv ./beszel-agent /opt/beszel-agent/beszel-agent
|
||||
sudo chown beszel:beszel /opt/beszel-agent/beszel-agent
|
||||
sudo chmod 755 /opt/beszel-agent/beszel-agent
|
||||
|
||||
# Create the systemd service
|
||||
echo "Creating the systemd service for the Beszel Agent..."
|
||||
sudo tee /etc/systemd/system/beszel-agent.service <<EOF
|
||||
[Unit]
|
||||
Description=Beszel Agent Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Environment="PORT=$PORT"
|
||||
Environment="KEY=$KEY"
|
||||
ExecStart=/opt/beszel-agent/beszel-agent
|
||||
User=beszel
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Load and start the service
|
||||
printf "\nLoading and starting the Beszel Agent service...\n"
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable beszel-agent.service
|
||||
sudo systemctl start beszel-agent.service
|
||||
|
||||
# Wait for the service to start or fail
|
||||
sleep 1
|
||||
|
||||
# Check if the service is running
|
||||
if [ "$(systemctl is-active beszel-agent.service)" != "active" ]; then
|
||||
echo "Error: The Beszel Agent service is not running."
|
||||
echo "$(systemctl status beszel-agent.service)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "The Beszel Agent has been installed and configured successfully! It is now running on port $PORT."
|
||||
fi
|
117
supplemental/scripts/install-hub.sh
Executable file
117
supplemental/scripts/install-hub.sh
Executable file
@@ -0,0 +1,117 @@
|
||||
#!/bin/bash
|
||||
version=0.0.1
|
||||
# Define default values
|
||||
|
||||
# Read command line options
|
||||
while getopts ":uh" opt; do
|
||||
case $opt in
|
||||
u) UNINSTALL="true";;
|
||||
h) printf "Beszel Hub installation script\n\n";
|
||||
printf "Usage: ./install-hub.sh [options]\n\n";
|
||||
printf "Options: \n"
|
||||
printf " -u : Uninstall the Beszel Hub\n";
|
||||
echo " -h : Display this help message";
|
||||
exit 0;;
|
||||
\?) echo "Invalid option: -$OPTARG"; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$UNINSTALL" = "true" ]; then
|
||||
# Stop and disable the Beszel Hub service
|
||||
echo "Stopping and disabling the Beszel Hub service..."
|
||||
sudo systemctl stop beszel-hub.service
|
||||
sudo systemctl disable beszel-hub.service
|
||||
|
||||
# Remove the systemd service file
|
||||
echo "Removing the systemd service file..."
|
||||
sudo rm /etc/systemd/system/beszel-hub.service
|
||||
|
||||
# Reload the systemd daemon
|
||||
echo "Reloading the systemd daemon..."
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
# Remove the Beszel Hub binary
|
||||
echo "Removing the Beszel Hub binary..."
|
||||
sudo rm /opt/beszel/beszel
|
||||
|
||||
# Remove the Beszel Hub directory
|
||||
echo "Removing the Beszel Hub directory..."
|
||||
sudo rm -rf /opt/beszel
|
||||
|
||||
# Remove the dedicated user
|
||||
echo "Removing the dedicated user..."
|
||||
sudo userdel beszel
|
||||
|
||||
echo "The Beszel Hub has been uninstalled successfully!"
|
||||
else
|
||||
# Function to check if a package is installed
|
||||
package_installed() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Check for package manager and install necessary packages if not installed
|
||||
if package_installed apt-get; then
|
||||
if ! package_installed tar || ! package_installed curl; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y tar curl
|
||||
fi
|
||||
elif package_installed yum; then
|
||||
if ! package_installed tar || ! package_installed curl; then
|
||||
sudo yum install -y tar curl
|
||||
fi
|
||||
elif package_installed pacman; then
|
||||
if ! package_installed tar || ! package_installed curl; then
|
||||
sudo pacman -Sy --noconfirm tar curl
|
||||
fi
|
||||
else
|
||||
echo "Warning: Please ensure 'tar' and 'curl' are installed."
|
||||
fi
|
||||
|
||||
# Create a dedicated user for the service if it doesn't exist
|
||||
if ! id -u beszel > /dev/null 2>&1; then
|
||||
echo "Creating a dedicated user for the Beszel Hub service..."
|
||||
sudo useradd -M -s /bin/false beszel
|
||||
fi
|
||||
|
||||
# Download and install the Beszel Hub
|
||||
echo "Downloading and installing the Beszel Hub..."
|
||||
curl -sL "https://github.com/henrygd/beszel/releases/latest/download/beszel_$(uname -s)_$(uname -m | sed 's/x86_64/amd64/' | sed 's/armv7l/arm/' | sed 's/aarch64/arm64/').tar.gz" | tar -xz -O beszel | tee ./beszel >/dev/null && chmod +x beszel
|
||||
sudo mkdir -p /opt/beszel/beszel_data
|
||||
sudo mv ./beszel /opt/beszel/beszel
|
||||
sudo chown -R beszel:beszel /opt/beszel
|
||||
|
||||
# Create the systemd service
|
||||
printf "Creating the systemd service for the Beszel Hub...\n\n"
|
||||
sudo tee /etc/systemd/system/beszel-hub.service <<EOF
|
||||
[Unit]
|
||||
Description=Beszel Hub Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/opt/beszel/beszel serve
|
||||
WorkingDirectory=/opt/beszel
|
||||
User=beszel
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Load and start the service
|
||||
printf "\nLoading and starting the Beszel Hub service...\n"
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable beszel-hub.service
|
||||
sudo systemctl start beszel-hub.service
|
||||
|
||||
# Wait for the service to start or fail
|
||||
sleep 2
|
||||
|
||||
# Check if the service is running
|
||||
if [ "$(systemctl is-active beszel-hub.service)" != "active" ]; then
|
||||
echo "Error: The Beszel Hub service is not running."
|
||||
echo "$(systemctl status beszel-hub.service)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "The Beszel Hub has been installed and configured successfully! It is now accessible on port 8090."
|
||||
fi
|
@@ -1,60 +0,0 @@
|
||||
## Run the hub as a system service (Linux)
|
||||
|
||||
This runs the hub in the background continuously using systemd.
|
||||
|
||||
1. Create the system service at `/etc/systemd/system/beszel.service`
|
||||
|
||||
```bash
|
||||
[Unit]
|
||||
Description=Beszel Hub Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
# update the values in the curly braces below (remove the braces)
|
||||
ExecStart={/path/to/working/directory}/beszel serve
|
||||
WorkingDirectory={/path/to/working/directory}
|
||||
User={YOUR_USERNAME}
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
2. Start and enable the service to let it run after system boot
|
||||
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable beszel.service
|
||||
sudo systemctl start beszel.service
|
||||
```
|
||||
|
||||
## Run the agent as a system service (Linux)
|
||||
|
||||
This runs the agent in the background continuously using systemd.
|
||||
|
||||
1. Create the system service at `/etc/systemd/system/beszel-agent.service`
|
||||
|
||||
```bash
|
||||
[Unit]
|
||||
Description=Beszel Agent Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
# update the values in curly braces below (remove the braces)
|
||||
Environment="PORT={PASTE_YOUR_PORT_HERE}"
|
||||
Environment="KEY={PASTE_YOUR_KEY_HERE}"
|
||||
ExecStart={/path/to/directory}/beszel-agent
|
||||
User={YOUR_USERNAME}
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
2. Start and enable the service to let it run after system boot
|
||||
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable beszel-agent.service
|
||||
sudo systemctl start beszel-agent.service
|
||||
```
|
Reference in New Issue
Block a user