30 Commits
1.0 ... main

Author SHA1 Message Date
25ed1ecf9b Update README.md 2025-01-29 09:11:16 +01:00
530e59e3e1 Remove clones repository, add some instructions 2025-01-28 10:20:04 +01:00
a156ae0c08 Update links 2025-01-22 11:22:33 +01:00
531b39db5d Change text 2025-01-22 11:18:57 +01:00
33e1ef965b Update README.md 2025-01-22 11:16:08 +01:00
f3606631a0 Check status 2025-01-22 11:10:52 +01:00
84ed566c55 Fix NSSM path 2025-01-22 11:01:56 +01:00
c4c5f2841c nssm status 2025-01-20 14:32:35 +01:00
0ecaefeb10 Create directory before nssm download 2025-01-20 10:49:29 +01:00
43a65926fe 64 bit only 2025-01-19 18:23:09 +01:00
24a6e7678e add finishing message 2025-01-19 18:13:04 +01:00
ae01d517d8 redirect winget output 2025-01-19 18:05:31 +01:00
581e856e50 --accept-source-agreements --accept-package-agreements 2025-01-19 18:02:49 +01:00
5e062cc429 Remove piping of output 2025-01-19 17:59:55 +01:00
0c93030488 Refresh environment 2025-01-19 17:56:58 +01:00
7b871edada Merge branch 'main' of https://gitea.elpatron.me/elpatron/Install-Beszel-Agent 2025-01-19 16:14:13 +01:00
58fb7067eb Merge branch 'main' of https://gitea.elpatron.me/elpatron/Install-Beszel-Agent 2025-01-19 16:14:06 +01:00
2ae4d963ea Merge branch 'main' of https://gitea.elpatron.me/elpatron/Install-Beszel-Agent 2025-01-19 16:12:17 +01:00
09ce390537 Update README.md 2025-01-19 16:12:04 +01:00
edc1df0bbd Update README.md 2025-01-19 16:10:22 +01:00
9706917679 Add missing scripts 2025-01-19 16:07:46 +01:00
f3d3a8472e Add env.cmd 2025-01-19 16:07:18 +01:00
39c458f321 Update README.md 2025-01-19 16:06:48 +01:00
683095b6d7 Move variables to env.cmd 2025-01-19 15:53:11 +01:00
281b3ce27d Add update_agent.cmd 2025-01-19 15:43:51 +01:00
3b730c162b Add build script 2025-01-19 14:37:37 +01:00
39069fe26d Typo, change text 2025-01-19 13:41:11 +01:00
9e6ba0da51 Redirect tar output 2025-01-19 13:39:34 +01:00
f5808f4461 Exception handling 2025-01-19 13:36:23 +01:00
ab8abaee85 Update README.md 2025-01-19 13:27:17 +01:00
8 changed files with 379 additions and 30 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/*.pdf
/*.zip
*.exe

141
README.md
View File

@@ -1,21 +1,142 @@
# Install Beszel Agent As Service Under Windows # BeszelWin
The Windows *cmd* file `install-beszel-service.cmd` installs the [Beszel](https://beszel.dev) agent as a service under Microsoft Windows. A collection of four scripts to build, install, update or uninstall the [Beszel](https://beszel.dev) agent under Microsoft Windows, inspired by [*Using Beszel to monitor Windows*](https://blog.ktz.me/using-beszel-to-monitor-windows/) and a [video](https://youtu.be/O_9wT-5LoHM) on the *Tailscale* channel by Alex Kretschmar.
## Usage ## (1) Building the executable
Open a `cmd.exe` shell with administrative rights. ### Prerequisites
- Microsoft Windows 10 or later **Client** OS (64 bit)
*Building under Windows Server OS should be working, but you have to install Go and Git manually as Winget is not available for Windows server operating systems.*
### Compiling
Download and extract [install-beszel-service.zip](https://gitea.elpatron.me/elpatron/Install-Beszel-Agent/releases/latest).
Open a `cmd.exe` shell, `cd` into the script directory (where you extracted the archive) and start the build-script:
```
.\build_agent.cmd
```
The script will install *Git* and *Go* (if not yet installed) with *Winget*, clone the *Beszel* repository and build a Windows 64 bit `agent.exe` binary.
```
C:\Users\User\Downloads\install-beszel-service>build_agent.cmd
This script downloads the Beszel repository and builds the Beszel agent for Windows (64 Bit only).
If not yet installed, Git and Go will be installed via Winget.
Winget executable found
Installing Go with Winget
Installing Git with Winget
Refreshing environment variables from registry for cmd.exe. Please wait...Finished..
Cloning Beszel repository
Building agent
Build successful
Beszel agent.exe was built and copied, you can proceed with 'install-beszel-service.cmd'.
```
## (2) Installing the service
### Prerequisites
- Microsoft Windows 10 or later - *Server OS should work, too*
### Installation
Open a `cmd.exe` shell with **administrative rights** and `cd` into the script directory (where you extracted the archive).
If you have built the agent by yourself: Copy your `agent.exe` binary to the directory where you extracted the scripts. Overwrite `agent.exe` from the archive.
Example:
```
copy /y .\beszel\beszel\cmd\agent\agent.exe .
```
Start the installation script provided with your Beszel Ssh key:
```` ````
git clone https://gitea.elpatron.me/elpatron/Install-Beszel-Agent
cd Install-Beszel-Agent
.\install-beszel-service.cmd <your Beszel ssh key> .\install-beszel-service.cmd <your Beszel ssh key>
```` ````
## Explanation The script copies `agent.exe` into the directory `%ProgramFiles%\BeszelAgent` and takes usage of *[NSSM - the Non-Sucking Service Manager](https://nssm.cc/)* to install the service. If *NSSM* is not yet installed on your system, it will be downloaded and installed to the Beszel agent directory.
The script copies `agent.exe` into the directory `%ProgramFiles%\BeszelAgent` and takes usage of *[NSSM - the Non-Sucking Service Manager](https://nssm.cc/)* to install the service. *NSSM* is being installed by *[Winget](https://github.com/microsoft/winget-cli)*. The provided `agent.exe` was compiled on January, 17th 2025 by me and should be exchanged by a self compiled or official executable, see *(1) Building the executable*.
The provided `agent.exe` was compiled on January, 18th 2025 by me and should be exchanged by a self compiled or official executable.
For more details, see [*Using Beszel to monitor Windows*](https://blog.ktz.me/using-beszel-to-monitor-windows/) by Alex Kretschmar. For more details, see [*Using Beszel to monitor Windows*](https://blog.ktz.me/using-beszel-to-monitor-windows/) by Alex Kretschmar.
```
C:\Users\User\Downloads\install-beszel-service>install-beszel-service.cmd ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJwRj3l7U9QUJM2K8p2mkH8KDJmhpMwejuPci4LtGxEz
This script installs the Beszel agent for Windows.
If not yet installed, NSSM will be installed via Winget.
Checking adminstrative rights
Administrative rights check OK
Creating directory C:\Program Files\BeszelAgent
Downloading NSSM
Extracting ZIP file
Copying nssm.exe to C:\Program Files\BeszelAgent
Deleting temporary files and directories
Copying agent.exe to C:\Program Files\BeszelAgent
Adding firewall rule
Installing service BeszelAgent
Setting environment for BeszelAgent
Starting BeszelAgent
BeszelAgent: START: The operation completed successfully.
Display service status
NSSM dump:
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" install BeszelAgent "C:\Program Files\BeszelAgent\agent.exe"
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent AppDirectory "C:\Program Files\BeszelAgent"
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent AppExit Default Restart
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent AppEnvironmentExtra ":KEY=ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJwRj3l7U9QUJM2K8p2mkH8KDJmhpMwejuPci4LtGxEz"
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent DisplayName BeszelAgent
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent ObjectName LocalSystem
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent Start SERVICE_AUTO_START
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent Type SERVICE_WIN32_OWN_PROCESS
Wait 5 seconds, check service status
SERVICE_RUNNING
```
## (3) Updating the service
### Prerequisites
- To update the Beszel agent, it has to be installed using the install script.
### Updating
Open a `cmd.exe` shell with **administrative rights** and `cd` into the script directory (where you extracted the archive).
Start the update by launching
```
.\update_agent.cmd
```
The update will make a fresh clone of the Beszel GitHub repository, build the executable, stop the agent service, copy the new `agent.exe` to `%ProgramFiles%\BeszelAgent` and start the service.
## (4) Uninstall the service
### Prerequisites
- To uninstall the Beszel agent, it has to be installed using the install script.
### Uninstalling
Open a `cmd.exe` shell with **administrative rights**.
Start the update by launching
```
.\uninstall_agent.cmd
```
The script will stop and remove the Beszel service and delete the installation directory `%ProgramFiles%\BeszelAgent`.

BIN
agent.exe

Binary file not shown.

67
build_agent.cmd Normal file
View File

@@ -0,0 +1,67 @@
@echo off
cd /D "%~dp0"
echo This script downloads the Beszel repository and builds the Beszel agent for Windows (64 Bit only).
echo If not yet installed, Git and Go will be installed via Winget.
echo.
call env.cmd
set REFRESHENV=0
where winget.exe >nul 2>&1
if %errorlevel% NEQ 0 (
echo Winget not found, install Winget or use a compatible OS: Win 10 Client OS or later
goto end
) else (
echo Winget executable found
)
where go.exe >nul 2>&1
if %errorlevel% NEQ 0 (
echo Installing Go with Winget
winget install GoLang.Go --accept-source-agreements --accept-package-agreements >nul 2>&1
set REFRESHENV=1
) else (
echo Go executable found
)
where git.exe >nul 2>&1
if %errorlevel% NEQ 0 (
echo Installing Git with Winget
winget install Git.Git --accept-source-agreements --accept-package-agreements >nul 2>&1
set REFRESHENV=1
) else (
echo Git executable found
)
if %REFRESHENV% EQU 1 call .\RefreshEnv.cmd
echo Cloning Beszel repository
git clone https://github.com/henrygd/beszel.git >nul 2>&1
if %errorlevel% NEQ 0 (
echo Cloning the Beszel repository failed.
goto end
)
cd .\beszel\beszel\cmd\agent
echo Building agent
go build -ldflags "-w -s" . >nul 2>&1
if %errorlevel% NEQ 0 (
echo Something went wrong
) else (
echo Build was successful
cd /D "%~dp0"
copy /y .\beszel\beszel\cmd\agent\agent.exe . >nul 2>&1
echo Beszel agent.exe was built and copied, you can proceed with 'install-beszel-service.cmd'.
rd /s/q .\beszel >nul 2>&1
echo Cloned Beszel repository was deleted as we don´t need it anymore.
echo.
echo You can go ahead with .\install-beszel-service.cmd to install the service.
echo .
echo If Git ond/or Go was installed from this script and you don´t want to keep them, use
echo winget uninstall GoLang.Go
echo winget uninstall Git.Git
echo to remove the corresponding packages.
)
:end

8
env.cmd Normal file
View File

@@ -0,0 +1,8 @@
@echo off
set SERVICENAME=BeszelAgent
set DESTINATIONDIR=%ProgramFiles%\%SERVICENAME%
set AGENTEXE=%DESTINATIONDIR%\agent.exe
set NSSMEXE=nssm.exe
set GOOS=windows
set GOARCH=amd64
set CGO_ENABLED=0

View File

@@ -1,57 +1,81 @@
@echo off @echo off
cd /D "%~dp0" cd /D "%~dp0"
echo This script installs the Beszel agent for Windows.
echo If not yet installed, NSSM will be installed via Winget.
echo.
echo Checking adminstrative rights
rem from https://stackoverflow.com/questions/7985755/how-to-detect-if-cmd-is-running-as-administrator-has-elevated-privileges
net session >nul 2>&1
if %errorlevel% equ 0 (
echo Administrative rights check OK
) else (
echo You are NOT Administrator. Start the script from an administrative cmd.exe shell...
goto end
)
if !%1==! goto help if !%1==! goto help
if !%2==! goto help if !%2==! goto help
set BESZELKEYPREFIX=%1 set BESZELKEYPREFIX=%1
set BESZELKEY=%2 set BESZELKEY=%2
set SERVICENAME=BeszelAgent call env.cmd
set DESTINATIONDIR=%ProgramFiles%\%SERVICENAME%
set AGENTEXE=%DESTINATIONDIR%\agent.exe echo Creating directory %DESTINATIONDIR%
set NSSMEXE=nssm.exe md "%DESTINATIONDIR%" >nul 2>&1
where nssm.exe >nul 2>&1 where nssm.exe >nul 2>&1
if %errorlevel%==1 goto installnssm if %errorlevel% NEQ 0 goto installnssm
goto proceed goto proceed
:installnssm :installnssm
echo Downloading NSSM echo Downloading NSSM
curl.exe --output "%TEMP%\nssm-2.24.zip" --url https://nssm.cc/release/nssm-2.24.zip >nul 2>&1 curl.exe --output "%TEMP%\nssm-2.24.zip" --url https://nssm.cc/ci/nssm-2.24-101-g897c7ad.zip >nul 2>&1
echo Extracting ZIP file echo Extracting ZIP file
tar.exe -xf %TEMP%\nssm-2.24.zip tar.exe -xf %TEMP%\nssm-2.24.zip >nul 2>&1
echo Copying nssm.exe to %DESTINATIONDIR% echo Copying nssm.exe to %DESTINATIONDIR%
if %PROCESSOR_ARCHITECTURE%==AMD64 ( copy .\nssm-2.24-101-g897c7ad\win64\nssm.exe "%DESTINATIONDIR%\" >nul 2>&1
copy .\nssm-2.24\win64\nssm.exe "%DESTINATIONDIR%\" >nul 2>&1
) else (
copy .\nssm-2.24\win32\nssm.exe "%DESTINATIONDIR%\" >nul 2>&1
)
set NSSMEXE="%DESTINATIONDIR%\nssm.exe" set NSSMEXE="%DESTINATIONDIR%\nssm.exe"
echo Deleting temporary files and directories echo Deleting temporary files and directories
del "%TEMP%\nssm-2.24.zip" >nul 2>&1 del "%TEMP%\nssm-2.24.zip" >nul 2>&1
rd /s/q .\nssm-2.24 >nul 2>&1 rd /s/q .\nssm-2.24 >nul 2>&1
:proceed :proceed
echo Creating deirectory %DESTINATIONDIR% echo Copying agent.exe to %DESTINATIONDIR%
md "%DESTINATIONDIR%" >nul 2>&1
echo Copying agent.exe
copy .\agent.exe "%DESTINATIONDIR%\" >nul 2>&1 copy .\agent.exe "%DESTINATIONDIR%\" >nul 2>&1
echo Adding firewall rule echo Adding firewall rule
netsh advfirewall firewall add rule name="%SERVICENAME%" dir=in action=allow program="%AGENTEXE%" enable=yes >nul 2>&1 netsh advfirewall firewall add rule name="%SERVICENAME%" dir=in action=allow program="%AGENTEXE%" enable=yes >nul 2>&1
echo Installing service echo Installing service %SERVICENAME%
%NSSMEXE% install %SERVICENAME% "%AGENTEXE%" >nul 2>&1 %NSSMEXE% install %SERVICENAME% "%AGENTEXE%" >nul 2>&1
if %errorlevel% NEQ 0 (
echo Failed to install the service.
goto end
)
echo Setting environment for %SERVICENAME%
%NSSMEXE% set %SERVICENAME% AppEnvironmentExtra "KEY=%BESZELKEYPREFIX% %BESZELKEY%" >nul 2>&1 %NSSMEXE% set %SERVICENAME% AppEnvironmentExtra "KEY=%BESZELKEYPREFIX% %BESZELKEY%" >nul 2>&1
if %errorlevel% NEQ 0 (
echo Failed to set the service environment.
goto end
)
echo Setting environment for service echo Starting %SERVICENAME%
%NSSMEXE% start %SERVICENAME% >nul 2>&1 %NSSMEXE% start %SERVICENAME%
if %errorlevel% NEQ 0 (
echo Check output above.
)
echo Service installed, status: echo NSSM dump:
%NSSMEXE% dump %SERVICENAME% %NSSMEXE% dump %SERVICENAME%
echo Wait 5 seconds, then check service status
ping 127.0.0.1 -n 5 >nul 2>&1
%NSSMEXE% status %SERVICENAME%
goto end goto end
:help :help
echo You have to provide a Beszel ssh key, e.g. 'install-beszel-service.cmd ssh-ed25519 AAAAC3L3lIpn94iu2TIpdmneXsEC1TDvrg4HCNoM1aiC683WMZfGOVoatrJSkysaQB9K echo You have to provide a Beszel ssh key, e.g. 'install-beszel-service.cmd ssh-ed25519 AAAAC3L3lIpn94iu2TIpdmneXsEC1TDvrg4HCNoM1aiC683WMZfGOVoatrJSkysaQB9K
echo The key must not be enclosed in "" or '', just copy and paste it as it is. echo The key must not be enclosed in "" or '', just copy and paste it as it is.
:end :end

29
uninstall_agent.cmd Normal file
View File

@@ -0,0 +1,29 @@
@echo off
setlocal
cd /D "%~dp0"
echo This script uninstalls the Beszel agent
echo.
call env.cmd
echo Checking adminstrative rights
rem from https://stackoverflow.com/questions/7985755/how-to-detect-if-cmd-is-running-as-administrator-has-elevated-privileges
net session >nul 2>&1
if %errorlevel% equ 0 (
echo Administrative rights check OK
) else (
echo You are NOT Administrator. Start the script from an administrative cmd.exe shell...
goto end
)
echo Stopping Beszel agent service
%NSSMEXE% stop %SERVICENAME% >nul 2>&1
echo Removing Beszel agent service
%NSSMEXE% remove %SERVICENAME% >nul 2>&1
echo Deleting installation directory
rd /q/s %DESTINATIONDIR% >nul 2>&1
:end
ech Done.

97
update_agent.cmd Normal file
View File

@@ -0,0 +1,97 @@
@echo off
setlocal
cd /D "%~dp0"
echo This script updates the Beszel agent to the latest version from the Github repository
echo.
echo Checking adminstrative rights
rem from https://stackoverflow.com/questions/7985755/how-to-detect-if-cmd-is-running-as-administrator-has-elevated-privileges
net session >nul 2>&1
if %errorlevel% equ 0 (
echo Administrative rights check OK
) else (
echo You are NOT Administrator. Start the script from an administrative cmd.exe shell...
goto end
)
call env.cmd
where winget.exe >nul 2>&1
if %errorlevel% NEQ 0 (
echo Winget not found, install Winget or use a compatible OS: Win 10 Client OS or later
goto end
) else (
echo Winget executable found
)
where go.exe >nul 2>&1
if %errorlevel% NEQ 0 (
echo Installing Go with Winget
winget install GoLang.Go
) else (
echo Go executable found
)
where git.exe >nul 2>&1
if %errorlevel% NEQ 0 (
echo Installing Git with Winget
winget install Git.Git
) else (
echo Git executable found
)
if exist .\beszel (
echo Subdirectory beszel already exists, it has to be deleted.
echo - Hit Crtl+c to exit if you don't want the directory to be deleted.
echo - Hit any other key to continue
pause >nul 2>&1
echo Deleting beszel subdirectory
rd /q/s .\beszel >nul 2>&1
)
:proceed
echo Cloning Beszel repository from Github
git clone https://github.com/henrygd/beszel.git >nul 2>&1
if %errorlevel% NEQ 0 (
echo Cloning repository failed.
goto end
)
cd .\beszel\beszel\cmd\agent
echo Building agent
set GOOS=windows
set GOARCH=amd64
set CGO_ENABLED=0
go build -ldflags "-w -s" . >nul 2>&1
if %errorlevel% NEQ 0 (
echo Something went wrong
goto end
) else (
echo Build successful
)
cd /D "%~dp0"
echo Stopping Beszel agent service
net stop %SERVICENAME% >nul 2>&1
if %errorlevel% NEQ 0 (
echo Failed to stop Beszel agent service
goto end
)
echo Copying new agent
copy .\beszel\beszel\cmd\agent\agent.exe %AGENTEXE% >nul 2>&1
if %errorlevel% NEQ 0 (
echo Failed to copy agent.exe
)
echo Starting Beszel agent service
net start %SERVICENAME% >nul 2>&1
if %errorlevel% NEQ 0 (
echo Failed to start Beszel agent service
goto end
)
:end
endlocal