feat: enhance LocalAGI installation with user creation and service hardening
This commit is contained in:
@@ -48,5 +48,10 @@
|
|||||||
"text": "To use an external Ollama host, edit `/opt/localagi/.env` and set `LOCALAGI_LLM_API_URL=http://<ollama-host>:11434/v1`, then restart LocalAGI with `systemctl restart localagi`.",
|
"text": "To use an external Ollama host, edit `/opt/localagi/.env` and set `LOCALAGI_LLM_API_URL=http://<ollama-host>:11434/v1`, then restart LocalAGI with `systemctl restart localagi`.",
|
||||||
"type": "info"
|
"type": "info"
|
||||||
}
|
}
|
||||||
|
,
|
||||||
|
{
|
||||||
|
"text": "The service runs as a dedicated system user `localagi` and the unit includes basic hardening (NoNewPrivileges, PrivateTmp, ProtectSystem).",
|
||||||
|
"type": "info"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ msg_ok "Installed Bun"
|
|||||||
|
|
||||||
fetch_and_deploy_gh_release "localagi" "mudler/LocalAGI" "tarball" "latest" "/opt/localagi"
|
fetch_and_deploy_gh_release "localagi" "mudler/LocalAGI" "tarball" "latest" "/opt/localagi"
|
||||||
|
|
||||||
|
if [[ ! -d /opt/localagi/webui/react-ui ]]; then
|
||||||
|
msg_error "Unexpected release layout: /opt/localagi/webui/react-ui not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
mkdir -p /opt/localagi/pool
|
mkdir -p /opt/localagi/pool
|
||||||
|
|
||||||
msg_info "Configuring LocalAGI"
|
msg_info "Configuring LocalAGI"
|
||||||
@@ -45,11 +50,29 @@ msg_ok "Configured LocalAGI"
|
|||||||
|
|
||||||
msg_info "Building LocalAGI from source"
|
msg_info "Building LocalAGI from source"
|
||||||
|
|
||||||
cd /opt/localagi/webui/react-ui &&
|
# Create dedicated system user to run the service
|
||||||
$STD bun install &&
|
if ! id -u localagi >/dev/null 2>&1; then
|
||||||
$STD bun run build &&
|
msg_info "Creating system user 'localagi'"
|
||||||
cd /opt/localagi &&
|
useradd --system --no-create-home --shell /usr/sbin/nologin --home /opt/localagi localagi || \
|
||||||
$STD go build -o /usr/local/bin/localagi
|
msg_warn "Failed to create 'localagi' user; continuing if it already exists"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure ownership and perms
|
||||||
|
chown -R localagi:localagi /opt/localagi || msg_warn "Failed to chown /opt/localagi"
|
||||||
|
|
||||||
|
cd /opt/localagi/webui/react-ui || { msg_error "Missing webui/react-ui directory"; exit 1; }
|
||||||
|
|
||||||
|
msg_info "Running bun install"
|
||||||
|
$STD bun install || { msg_error "bun install failed"; exit 1; }
|
||||||
|
|
||||||
|
msg_info "Building web UI"
|
||||||
|
$STD bun run build || { msg_error "bun build failed"; exit 1; }
|
||||||
|
|
||||||
|
cd /opt/localagi || { msg_error "Missing /opt/localagi"; exit 1; }
|
||||||
|
|
||||||
|
msg_info "Building Go binary"
|
||||||
|
$STD go build -o /usr/local/bin/localagi || { msg_error "go build failed"; exit 1; }
|
||||||
|
chmod 755 /usr/local/bin/localagi || msg_warn "Failed to chmod /usr/local/bin/localagi"
|
||||||
msg_ok "Built LocalAGI from source"
|
msg_ok "Built LocalAGI from source"
|
||||||
|
|
||||||
msg_info "Creating Service"
|
msg_info "Creating Service"
|
||||||
@@ -62,7 +85,15 @@ After=network.target
|
|||||||
Type=simple
|
Type=simple
|
||||||
WorkingDirectory=/opt/localagi
|
WorkingDirectory=/opt/localagi
|
||||||
EnvironmentFile=/opt/localagi/.env
|
EnvironmentFile=/opt/localagi/.env
|
||||||
|
User=localagi
|
||||||
ExecStart=/usr/local/bin/localagi
|
ExecStart=/usr/local/bin/localagi
|
||||||
|
NoNewPrivileges=true
|
||||||
|
PrivateTmp=true
|
||||||
|
ProtectSystem=full
|
||||||
|
ProtectHome=true
|
||||||
|
AmbientCapabilities=
|
||||||
|
StandardOutput=journal
|
||||||
|
StandardError=journal
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user