-
Notifications
You must be signed in to change notification settings - Fork 1
How to upgrade agent (systemd and version tag)
LaV edited this page Jul 29, 2025
·
3 revisions
It is possible to upgrade your agent from netbox with the following setup.
Use systemd with a similar configuration :
[Unit]
Description=Netbox Docker Agent
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/docker run -p 1880:1880 -e ENABLE_EDITOR=1 -v /var/run/docker.sock:/var/run/docker.sock:rw -v netbox-docker-agent:/data --name netbox-docker-agent saashup/netbox-docker-agent
ExecStop=/usr/bin/docker stop netbox-docker-agent
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target
upgrade-agent.sh script :
#!/bin/bash
_quit(){
local retCode="$1" msg="${*:2}"
printf '%s\n' "$msg"
exit "$retCode"
}
: "${DEBUG:=0}"
: "${API_USERNAME:=admin}"
: "${API_PASSWORD=\$2a\$08\$s.NFdSn4Gm4d7gHErya//e6O8RO1/3f7TZ7zflXJ9jfFV0cI6jGwK}"
: "${ADMIN_USER:=admin}"
: "${ADMIN_PASSWORD=\$2a\$08\$s.NFdSn4Gm4d7gHErya//e6O8RO1/3f7TZ7zflXJ9jfFV0cI6jGwK}"
: "${PORT:=1880}"
: "${DOCKER_SOCKET:=/var/run/docker.sock}"
extra_args=(
"-e API_USERNAME=${API_USERNAME}"
"-e API_PASSWORD=${API_PASSWORD}"
"-e ADMIN_USER=${ADMIN_USER}"
"-e ADMIN_PASSWORD=${ADMIN_PASSWORD}"
)
[[ -n "$ENABLE_EDITOR" ]] && extra_args+=("-e ENABLE_EDITOR=1")
[[ -n "$DISABLE_EXEC" ]] && extra_args+=("-e DISABLE_EXEC=1")
[[ -n "$DISABLE_SSL_CHECK" ]] && extra_args+=("-e DISABLE_SSL_CHECK=1")
[[ -n "$NODE_EXTRA_CA_CERTS" ]] && extra_args+=("-e NODE_EXTRA_CA_CERTS=${NODE_EXTRA_CA_CERTS}")
[[ -n "$NETBOX_URL" ]] && extra_args+=("-e NETBOX_URL=${NETBOX_URL}")
if (( DEBUG > 0 )); then
set -x
_run="echo"
else
_run=""
fi
docker_run() {
$_run docker run --name "$container_name" -v "${DOCKER_SOCKET}:/var/run/docker.sock:rw" -v netbox-docker-agent:/data "${extra_args[@]}" -p "${PORT}:1880" "${image_name}:${latest_release[0]}"
}
for bin in curl jq docker; do
type "$bin" &>/dev/null || _quit 1 "Required binary '$bin' not found. Please install it."
done
image_name="saashup/netbox-docker-agent"
arch_name="amd64"
container_name="netbox-docker-agent"
mapfile -t latest_release < <(curl -s "[https://registry.hub.docker.com/v2/repositories/${image_name}/tags/?page_size=100"](https://registry.hub.docker.com/v2/repositories/$%7Bimage_name%7D/tags/?page_size=100%22) | jq --arg arch "$arch_name" -r '.results[] | select((.images[]?.architecture==$arch) and (.name|test("v.*")) ) | .name ' )
[[ ${#latest_release[@]} -eq 0 ]] && _quit 1 "No releases found for image '$image_name' with architecture '$arch_name'."
image_sha="$(docker inspect --format='{{ index .Image }}' "$container_name")"
image_version="$(docker image inspect --format='{{index .RepoTags 0 }}' "${image_sha/sha256:/}")"
if [[ -z "$image_sha" ]]; then
docker_run
_quit 0 "Container '$container_name' started with the latest image version '${latest_release[0]}'."
fi
if [[ -z "$image_version" ]]; then
docker_run
_quit 0 "Container '$container_name' started with the latest image version '${latest_release[0]}'."
fi
if [[ "${image_version##*:}" != "${latest_release[0]}" ]]; then
printf 'Updating container "%s" to version "%s" ... \n' "$container_name" "${latest_release[0]}"
$_run docker pull "${image_name}:${latest_release[0]}" || _quit 1 "Failed to pull the latest image."
$_run docker stop "$container_name" || _quit 1 "Failed to stop the container '$container_name'."
$_run docker rm "$container_name" || _quit 1 "Failed to remove the container '$container_name'."
docker_run || _quit 1 "Failed to start the new container with the latest image."
_quit 0 "Container '$container_name' updated successfully to version '${latest_release[0]}'."
else
_quit 0 "Container '$container_name' is already up-to-date with version '${image_version##*:}'."
fi
If you run the netbox-docker-agent with this configuration you can then connect to your netbox to upgrade.
Go on the host you want to upgrade and check version and status :
Then select the netbox-docker-agent container on this host :
Click on the stop Button :
By stopping the container systemd will detect it and launch the pull / delete and create of the netbox-docker-agent container.
Going back on the Host you will see a new netbox-docker-agent container. Select it and check the status :
Going back on the host page you will see the new version of the host agent :
Voila! Your agent is up to date.