chore: clarify auto-update feature

This commit is contained in:
tigattack
2025-09-26 23:24:34 +01:00
parent be3fe52aea
commit c886b812d6
5 changed files with 62 additions and 62 deletions

View File

@@ -821,7 +821,7 @@ EOF
success "Update sent successfully" success "Update sent successfully"
echo "$response" | grep -o '"packagesProcessed":[0-9]*' | cut -d':' -f2 | xargs -I {} info "Processed {} packages" echo "$response" | grep -o '"packagesProcessed":[0-9]*' | cut -d':' -f2 | xargs -I {} info "Processed {} packages"
# Check for auto-update instructions (look specifically in autoUpdate section) # Check for PatchMon agent update instructions (this updates the agent script, not system packages)
if echo "$response" | grep -q '"autoUpdate":{'; then if echo "$response" | grep -q '"autoUpdate":{'; then
local auto_update_section=$(echo "$response" | grep -o '"autoUpdate":{[^}]*}') local auto_update_section=$(echo "$response" | grep -o '"autoUpdate":{[^}]*}')
local should_update=$(echo "$auto_update_section" | grep -o '"shouldUpdate":true' | cut -d':' -f2) local should_update=$(echo "$auto_update_section" | grep -o '"shouldUpdate":true' | cut -d':' -f2)
@@ -830,15 +830,15 @@ EOF
local current_version=$(echo "$auto_update_section" | grep -o '"currentVersion":"[^"]*' | cut -d'"' -f4) local current_version=$(echo "$auto_update_section" | grep -o '"currentVersion":"[^"]*' | cut -d'"' -f4)
local update_message=$(echo "$auto_update_section" | grep -o '"message":"[^"]*' | cut -d'"' -f4) local update_message=$(echo "$auto_update_section" | grep -o '"message":"[^"]*' | cut -d'"' -f4)
info "Auto-update detected: $update_message" info "PatchMon agent update detected: $update_message"
info "Current version: $current_version, Latest version: $latest_version" info "Current version: $current_version, Latest version: $latest_version"
# Automatically run update-agent command # Automatically run update-agent command to update the PatchMon agent script
info "Automatically updating agent to latest version..." info "Automatically updating PatchMon agent to latest version..."
if "$0" update-agent; then if "$0" update-agent; then
success "Agent auto-update completed successfully" success "PatchMon agent update completed successfully"
else else
warning "Agent auto-update failed, but data was sent successfully" warning "PatchMon agent update failed, but data was sent successfully"
fi fi
fi fi
fi fi

View File

@@ -158,8 +158,8 @@ else
warning "Initial package data failed, but agent is configured. You can run 'patchmon-agent.sh update' manually." warning "Initial package data failed, but agent is configured. You can run 'patchmon-agent.sh update' manually."
fi fi
# Setup crontab for automatic updates # Setup crontab for automatic package status updates
info "⏰ Setting up automatic updates every $UPDATE_INTERVAL minutes..." info "⏰ Setting up automatic package status update every $UPDATE_INTERVAL minutes..."
if [[ $UPDATE_INTERVAL -eq 60 ]]; then if [[ $UPDATE_INTERVAL -eq 60 ]]; then
# Hourly updates # Hourly updates
echo "0 * * * * /usr/local/bin/patchmon-agent.sh update >/dev/null 2>&1" | crontab - echo "0 * * * * /usr/local/bin/patchmon-agent.sh update >/dev/null 2>&1" | crontab -
@@ -179,7 +179,7 @@ if [[ "$EXPECTED_VERSION" != "Unknown" ]]; then
fi fi
echo " • Config directory: /etc/patchmon/" echo " • Config directory: /etc/patchmon/"
echo " • Credentials file: /etc/patchmon/credentials" echo " • Credentials file: /etc/patchmon/credentials"
echo "Automatic updates: Every $UPDATE_INTERVAL minutes via crontab" echo "Status updates: Every $UPDATE_INTERVAL minutes via crontab"
echo " • View logs: tail -f /var/log/patchmon-agent.log" echo " • View logs: tail -f /var/log/patchmon-agent.log"
echo "" echo ""
echo "🔧 Manual commands:" echo "🔧 Manual commands:"

View File

@@ -527,11 +527,11 @@ router.post(
}); });
}); });
// Check if auto-update is enabled and if there's a newer agent version available // Check if agent auto-update is enabled and if there's a newer version available
let autoUpdateResponse = null; let autoUpdateResponse = null;
try { try {
const settings = await prisma.settings.findFirst(); const settings = await prisma.settings.findFirst();
// Check both global auto-update setting AND host-specific auto-update setting // Check both global agent auto-update setting AND host-specific agent auto-update setting
if (settings?.auto_update && host.auto_update) { if (settings?.auto_update && host.auto_update) {
// Get current agent version from the request // Get current agent version from the request
const currentAgentVersion = req.body.agentVersion; const currentAgentVersion = req.body.agentVersion;
@@ -560,8 +560,8 @@ router.post(
} }
} }
} catch (error) { } catch (error) {
console.error("Auto-update check error:", error); console.error("Agent auto-update check error:", error);
// Don't fail the update if auto-update check fails // Don't fail the update if agent auto-update check fails
} }
const response = { const response = {
@@ -571,7 +571,7 @@ router.post(
securityUpdates: securityCount, securityUpdates: securityCount,
}; };
// Add auto-update response if available // Add agent auto-update response if available
if (autoUpdateResponse) { if (autoUpdateResponse) {
response.autoUpdate = autoUpdateResponse; response.autoUpdate = autoUpdateResponse;
} }
@@ -1060,7 +1060,7 @@ router.delete(
}, },
); );
// Toggle host auto-update setting // Toggle agent auto-update setting
router.patch( router.patch(
"/:hostId/auto-update", "/:hostId/auto-update",
authenticateToken, authenticateToken,
@@ -1068,7 +1068,7 @@ router.patch(
[ [
body("auto_update") body("auto_update")
.isBoolean() .isBoolean()
.withMessage("Auto-update must be a boolean"), .withMessage("Agent auto-update setting must be a boolean"),
], ],
async (req, res) => { async (req, res) => {
try { try {
@@ -1089,7 +1089,7 @@ router.patch(
}); });
res.json({ res.json({
message: `Host auto-update ${auto_update ? "enabled" : "disabled"} successfully`, message: `Agent auto-update ${auto_update ? "enabled" : "disabled"} successfully`,
host: { host: {
id: host.id, id: host.id,
friendlyName: host.friendly_name, friendlyName: host.friendly_name,
@@ -1097,8 +1097,8 @@ router.patch(
}, },
}); });
} catch (error) { } catch (error) {
console.error("Host auto-update toggle error:", error); console.error("Agent auto-update toggle error:", error);
res.status(500).json({ error: "Failed to toggle host auto-update" }); res.status(500).json({ error: "Failed to toggle agent auto-update" });
} }
}, },
); );

View File

@@ -84,7 +84,7 @@ const HostDetail = () => {
}, },
}); });
// Toggle auto-update mutation // Toggle agent auto-update mutation (updates PatchMon agent script, not system packages)
const toggleAutoUpdateMutation = useMutation({ const toggleAutoUpdateMutation = useMutation({
mutationFn: (auto_update) => mutationFn: (auto_update) =>
adminHostsAPI adminHostsAPI
@@ -350,7 +350,7 @@ const HostDetail = () => {
<div className="space-y-4"> <div className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4"> <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div> <div>
<p className="text-xs text-secondary-500 dark:text-secondary-300 mb-1"> <p className="text-xs text-secondary-500 dark:text-secondary-300 mb-1.5">
Friendly Name Friendly Name
</p> </p>
<InlineEdit <InlineEdit
@@ -374,7 +374,7 @@ const HostDetail = () => {
{host.hostname && ( {host.hostname && (
<div> <div>
<p className="text-xs text-secondary-500 dark:text-secondary-300"> <p className="text-xs text-secondary-500 dark:text-secondary-300 mb-1.5">
System Hostname System Hostname
</p> </p>
<p className="font-medium text-secondary-900 dark:text-white font-mono text-sm"> <p className="font-medium text-secondary-900 dark:text-white font-mono text-sm">
@@ -384,7 +384,7 @@ const HostDetail = () => {
)} )}
<div> <div>
<p className="text-xs text-secondary-500 dark:text-secondary-300"> <p className="text-xs text-secondary-500 dark:text-secondary-300 mb-1.5">
Host Group Host Group
</p> </p>
{host.host_groups ? ( {host.host_groups ? (
@@ -402,7 +402,7 @@ const HostDetail = () => {
</div> </div>
<div> <div>
<p className="text-xs text-secondary-500 dark:text-secondary-300"> <p className="text-xs text-secondary-500 dark:text-secondary-300 mb-1.5">
Operating System Operating System
</p> </p>
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
@@ -413,43 +413,38 @@ const HostDetail = () => {
</div> </div>
</div> </div>
{host.agent_version && ( <div>
<div className="flex items-center justify-between"> <p className="text-xs text-secondary-500 dark:text-secondary-300 mb-1.5">
<div> Agent Version
<p className="text-xs text-secondary-500 dark:text-secondary-300"> </p>
Agent Version <p className="font-medium text-secondary-900 dark:text-white text-sm">
</p> {host.agent_version || "Unknown"}
<p className="font-medium text-secondary-900 dark:text-white text-sm"> </p>
{host.agent_version} </div>
</p>
</div> <div>
<div className="flex items-center gap-2"> <p className="text-xs text-secondary-500 dark:text-secondary-300 mb-1.5">
<span className="text-xs text-secondary-500 dark:text-secondary-300"> Auto-update
Auto-update </p>
</span> <button
<button type="button"
type="button" onClick={() =>
onClick={() => toggleAutoUpdateMutation.mutate(!host.auto_update)
toggleAutoUpdateMutation.mutate(!host.auto_update) }
} disabled={toggleAutoUpdateMutation.isPending}
disabled={toggleAutoUpdateMutation.isPending} className={`relative inline-flex h-5 w-9 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 ${
className={`relative inline-flex h-5 w-9 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 ${ host.auto_update
host.auto_update ? "bg-primary-600 dark:bg-primary-500"
? "bg-primary-600 dark:bg-primary-500" : "bg-secondary-200 dark:bg-secondary-600"
: "bg-secondary-200 dark:bg-secondary-600" }`}
}`} >
> <span
<span className={`inline-block h-3 w-3 transform rounded-full bg-white transition-transform ${
className={`inline-block h-3 w-3 transform rounded-full bg-white transition-transform ${ host.auto_update ? "translate-x-5" : "translate-x-1"
host.auto_update }`}
? "translate-x-5" />
: "translate-x-1" </button>
}`} </div>
/>
</button>
</div>
</div>
)}
</div> </div>
</div> </div>
)} )}

View File

@@ -326,7 +326,12 @@ const Hosts = () => {
{ id: "os", label: "OS", visible: true, order: 4 }, { id: "os", label: "OS", visible: true, order: 4 },
{ id: "os_version", label: "OS Version", visible: false, order: 5 }, { id: "os_version", label: "OS Version", visible: false, order: 5 },
{ id: "agent_version", label: "Agent Version", visible: true, order: 6 }, { id: "agent_version", label: "Agent Version", visible: true, order: 6 },
{ id: "auto_update", label: "Auto-update", visible: true, order: 7 }, {
id: "auto_update",
label: "Agent Auto-Update",
visible: true,
order: 7,
},
{ id: "status", label: "Status", visible: true, order: 8 }, { id: "status", label: "Status", visible: true, order: 8 },
{ id: "updates", label: "Updates", visible: true, order: 9 }, { id: "updates", label: "Updates", visible: true, order: 9 },
{ id: "last_update", label: "Last Update", visible: true, order: 10 }, { id: "last_update", label: "Last Update", visible: true, order: 10 },