mirror of
https://github.com/henrygd/beszel.git
synced 2026-04-21 20:21:49 +02:00
Compare commits
5 Commits
v0.18.3
...
221be1da58
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
221be1da58 | ||
|
|
8347afd68e | ||
|
|
2a3885a52e | ||
|
|
5452e50080 | ||
|
|
028f7bafb2 |
@@ -238,7 +238,9 @@ func (a *Agent) getFingerprint() string {
|
|||||||
// first look for a fingerprint in the data directory
|
// first look for a fingerprint in the data directory
|
||||||
if a.dataDir != "" {
|
if a.dataDir != "" {
|
||||||
if fp, err := os.ReadFile(filepath.Join(a.dataDir, "fingerprint")); err == nil {
|
if fp, err := os.ReadFile(filepath.Join(a.dataDir, "fingerprint")); err == nil {
|
||||||
return string(fp)
|
if s := strings.TrimSpace(string(fp)); s != "" {
|
||||||
|
return s
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ var hubVersions map[string]semver.Version
|
|||||||
// and begins listening for connections. Returns an error if the server
|
// and begins listening for connections. Returns an error if the server
|
||||||
// is already running or if there's an issue starting the server.
|
// is already running or if there's an issue starting the server.
|
||||||
func (a *Agent) StartServer(opts ServerOptions) error {
|
func (a *Agent) StartServer(opts ServerOptions) error {
|
||||||
|
if disableSSH, _ := GetEnv("DISABLE_SSH"); disableSSH == "true" {
|
||||||
|
return errors.New("SSH disabled")
|
||||||
|
}
|
||||||
if a.server != nil {
|
if a.server != nil {
|
||||||
return errors.New("server already started")
|
return errors.New("server already started")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
//go:build testing
|
||||||
|
// +build testing
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -180,6 +183,23 @@ func TestStartServer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStartServerDisableSSH(t *testing.T) {
|
||||||
|
os.Setenv("BESZEL_AGENT_DISABLE_SSH", "true")
|
||||||
|
defer os.Unsetenv("BESZEL_AGENT_DISABLE_SSH")
|
||||||
|
|
||||||
|
agent, err := NewAgent("")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
opts := ServerOptions{
|
||||||
|
Network: "tcp",
|
||||||
|
Addr: ":45990",
|
||||||
|
}
|
||||||
|
|
||||||
|
err = agent.StartServer(opts)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), "SSH disabled")
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
//////////////////// ParseKeys Tests ////////////////////////////
|
//////////////////// ParseKeys Tests ////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -31,9 +31,6 @@ func (opts *cmdOptions) parse() bool {
|
|||||||
|
|
||||||
// Subcommands that don't require any pflag parsing
|
// Subcommands that don't require any pflag parsing
|
||||||
switch subcommand {
|
switch subcommand {
|
||||||
case "-v", "version":
|
|
||||||
fmt.Println(beszel.AppName+"-agent", beszel.Version)
|
|
||||||
return true
|
|
||||||
case "health":
|
case "health":
|
||||||
err := health.Check()
|
err := health.Check()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -49,6 +46,7 @@ func (opts *cmdOptions) parse() bool {
|
|||||||
pflag.StringVarP(&opts.hubURL, "url", "u", "", "URL of the Beszel hub")
|
pflag.StringVarP(&opts.hubURL, "url", "u", "", "URL of the Beszel hub")
|
||||||
pflag.StringVarP(&opts.token, "token", "t", "", "Token to use for authentication")
|
pflag.StringVarP(&opts.token, "token", "t", "", "Token to use for authentication")
|
||||||
chinaMirrors := pflag.BoolP("china-mirrors", "c", false, "Use mirror for update (gh.beszel.dev) instead of GitHub")
|
chinaMirrors := pflag.BoolP("china-mirrors", "c", false, "Use mirror for update (gh.beszel.dev) instead of GitHub")
|
||||||
|
version := pflag.BoolP("version", "v", false, "Show version information")
|
||||||
help := pflag.BoolP("help", "h", false, "Show this help message")
|
help := pflag.BoolP("help", "h", false, "Show this help message")
|
||||||
|
|
||||||
// Convert old single-dash long flags to double-dash for backward compatibility
|
// Convert old single-dash long flags to double-dash for backward compatibility
|
||||||
@@ -86,6 +84,9 @@ func (opts *cmdOptions) parse() bool {
|
|||||||
|
|
||||||
// Must run after pflag.Parse()
|
// Must run after pflag.Parse()
|
||||||
switch {
|
switch {
|
||||||
|
case *version:
|
||||||
|
fmt.Println(beszel.AppName+"-agent", beszel.Version)
|
||||||
|
return true
|
||||||
case *help || subcommand == "help":
|
case *help || subcommand == "help":
|
||||||
pflag.Usage()
|
pflag.Usage()
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import type { ClassValue } from "clsx"
|
|||||||
import {
|
import {
|
||||||
ArrowUpDownIcon,
|
ArrowUpDownIcon,
|
||||||
ChevronRightSquareIcon,
|
ChevronRightSquareIcon,
|
||||||
|
ClockArrowUp,
|
||||||
CopyIcon,
|
CopyIcon,
|
||||||
CpuIcon,
|
CpuIcon,
|
||||||
HardDriveIcon,
|
HardDriveIcon,
|
||||||
@@ -34,6 +35,7 @@ import {
|
|||||||
formatTemperature,
|
formatTemperature,
|
||||||
getMeterState,
|
getMeterState,
|
||||||
parseSemVer,
|
parseSemVer,
|
||||||
|
secondsToString,
|
||||||
} from "@/lib/utils"
|
} from "@/lib/utils"
|
||||||
import { batteryStateTranslations } from "@/lib/i18n"
|
import { batteryStateTranslations } from "@/lib/i18n"
|
||||||
import type { SystemRecord } from "@/types"
|
import type { SystemRecord } from "@/types"
|
||||||
@@ -373,6 +375,29 @@ export function SystemsTableColumns(viewMode: "table" | "grid"): ColumnDef<Syste
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
accessorFn: ({ info }) => info.u || undefined,
|
||||||
|
id: "uptime",
|
||||||
|
name: () => t`Uptime`,
|
||||||
|
size: 50,
|
||||||
|
Icon: ClockArrowUp,
|
||||||
|
header: sortableHeader,
|
||||||
|
cell(info) {
|
||||||
|
const uptime = info.getValue() as number
|
||||||
|
if (!uptime) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
let formatted: string
|
||||||
|
if (uptime < 3600) {
|
||||||
|
formatted = secondsToString(uptime, "minute")
|
||||||
|
} else if (uptime < 360000) {
|
||||||
|
formatted = secondsToString(uptime, "hour")
|
||||||
|
} else {
|
||||||
|
formatted = secondsToString(uptime, "day")
|
||||||
|
}
|
||||||
|
return <span className="tabular-nums whitespace-nowrap">{formatted}</span>
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
accessorFn: ({ info }) => info.v,
|
accessorFn: ({ info }) => info.v,
|
||||||
id: "agent",
|
id: "agent",
|
||||||
|
|||||||
@@ -7,13 +7,15 @@ param (
|
|||||||
[int]$Port = 45876,
|
[int]$Port = 45876,
|
||||||
[string]$AgentPath = "",
|
[string]$AgentPath = "",
|
||||||
[string]$NSSMPath = "",
|
[string]$NSSMPath = "",
|
||||||
[switch]$ConfigureFirewall
|
[switch]$ConfigureFirewall,
|
||||||
|
[ValidateSet("Auto", "Scoop", "WinGet")]
|
||||||
|
[string]$InstallMethod = "Auto"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if required parameters are provided
|
# Check if required parameters are provided
|
||||||
if ([string]::IsNullOrWhiteSpace($Key)) {
|
if ([string]::IsNullOrWhiteSpace($Key)) {
|
||||||
Write-Host "ERROR: SSH Key is required." -ForegroundColor Red
|
Write-Host "ERROR: SSH Key is required." -ForegroundColor Red
|
||||||
Write-Host "Usage: .\install-agent.ps1 -Key 'your-ssh-key-here' [-Token 'your-token-here'] [-Url 'your-hub-url-here'] [-Port port-number] [-ConfigureFirewall]" -ForegroundColor Yellow
|
Write-Host "Usage: .\install-agent.ps1 -Key 'your-ssh-key-here' [-Token 'your-token-here'] [-Url 'your-hub-url-here'] [-Port port-number] [-InstallMethod Auto|Scoop|WinGet] [-ConfigureFirewall]" -ForegroundColor Yellow
|
||||||
Write-Host "Note: Token and Url are optional for backwards compatibility with older hub versions." -ForegroundColor Yellow
|
Write-Host "Note: Token and Url are optional for backwards compatibility with older hub versions." -ForegroundColor Yellow
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -486,18 +488,34 @@ try {
|
|||||||
Write-Host "2. Install WinGet and run this script again" -ForegroundColor Yellow
|
Write-Host "2. Install WinGet and run this script again" -ForegroundColor Yellow
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Test-CommandExists "scoop") {
|
if ($InstallMethod -eq "Scoop") {
|
||||||
|
if (-not (Test-CommandExists "scoop")) {
|
||||||
|
throw "InstallMethod is set to Scoop, but Scoop is not available in PATH."
|
||||||
|
}
|
||||||
Write-Host "Using Scoop for installation..."
|
Write-Host "Using Scoop for installation..."
|
||||||
$AgentPath = Install-WithScoop -Key $Key -Port $Port
|
$AgentPath = Install-WithScoop -Key $Key -Port $Port
|
||||||
}
|
}
|
||||||
elseif (Test-CommandExists "winget") {
|
elseif ($InstallMethod -eq "WinGet") {
|
||||||
|
if (-not (Test-CommandExists "winget")) {
|
||||||
|
throw "InstallMethod is set to WinGet, but WinGet is not available in PATH."
|
||||||
|
}
|
||||||
Write-Host "Using WinGet for installation..."
|
Write-Host "Using WinGet for installation..."
|
||||||
$AgentPath = Install-WithWinGet -Key $Key -Port $Port
|
$AgentPath = Install-WithWinGet -Key $Key -Port $Port
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Host "Neither Scoop nor WinGet is installed. Installing Scoop..."
|
if (Test-CommandExists "scoop") {
|
||||||
$AgentPath = Install-WithScoop -Key $Key -Port $Port
|
Write-Host "Using Scoop for installation..."
|
||||||
|
$AgentPath = Install-WithScoop -Key $Key -Port $Port
|
||||||
|
}
|
||||||
|
elseif (Test-CommandExists "winget") {
|
||||||
|
Write-Host "Using WinGet for installation..."
|
||||||
|
$AgentPath = Install-WithWinGet -Key $Key -Port $Port
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host "Neither Scoop nor WinGet is installed. Installing Scoop..."
|
||||||
|
$AgentPath = Install-WithScoop -Key $Key -Port $Port
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,7 +579,8 @@ try {
|
|||||||
"-Token", "`"$Token`"",
|
"-Token", "`"$Token`"",
|
||||||
"-Url", "`"$Url`"",
|
"-Url", "`"$Url`"",
|
||||||
"-Port", $Port,
|
"-Port", $Port,
|
||||||
"-AgentPath", "`"$AgentPath`""
|
"-AgentPath", "`"$AgentPath`"",
|
||||||
|
"-InstallMethod", $InstallMethod
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add NSSMPath if we found it
|
# Add NSSMPath if we found it
|
||||||
|
|||||||
Reference in New Issue
Block a user