×
Update Netprobe
This CloudFormation template updates Netprobe on existing EC2 instances using AWS Systems Manager (SSM). It stops the existing service, backs up the current netprobe
directory, removes it, downloads the new Netprobe package and setup file from S3, restores ownership, and restarts netprobe.service
.
Prerequisites Copied
- Target EC2 instances must have SSM Agent installed and running
- Target instances must have an IAM instance profile attached with permissions:
AmazonSSMManagedInstanceCore
(for SSM communication)- S3 read access to the Netprobe artifacts bucket (and KMS decrypt if applicable)
- The
netprobe.service
systemd unit should already exist on the instances - An existing Netprobe installation directory at
<NetprobeInstallDirectory>/netprobe
(the update verifies this and aborts if missing) - Netprobe package and setup file available in S3 at the provided URLs
Input Parameters Copied
Parameter | Description | Default | Required |
---|---|---|---|
Target EC2 Configuration | |||
InstanceIds |
Comma-separated list of existing EC2 Instance IDs | - | ✓ |
AWS Credentials | |||
AWSRegion |
AWS Region (e.g., ap-southeast-1, us-west-2) | ap-southeast-1 | |
Netprobe Configuration | |||
NetprobeInstallDirectory |
Directory where Netprobe will be installed | ~/geneos | |
S3NetprobeURL |
S3 URL to the Netprobe tar.gz file | - | ✓ |
S3NetprobeSetupURL |
S3 URL to the Netprobe setup XML file | - | ✓ |
Configuration Copied
AWSTemplateFormatVersion: '2010-09-09'
Description: Configure existing EC2 instances with Netprobe setup using AWS Systems Manager
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "Target EC2 Configuration"
Parameters:
- InstanceIds
- Label:
default: "AWS Credentials"
Parameters:
- AWSRegion
- Label:
default: "Netprobe Configuration"
Parameters:
- NetprobeInstallDirectory
- S3NetprobeURL
- S3NetprobeSetupURL
ParameterLabels:
InstanceIds:
default: "Target EC2 Instance IDs"
AWSRegion:
default: "AWS Region"
NetprobeInstallDirectory:
default: "Netprobe Installation Directory"
S3NetprobeURL:
default: "S3 URL for Netprobe"
S3NetprobeSetupURL:
default: "S3 URL for Netprobe Setup File"
Parameters:
InstanceIds:
Type: CommaDelimitedList
Description: Comma-separated list of existing EC2 Instance IDs
AWSRegion:
Type: String
Description: AWS Region for CLI configuration (e.g., ap-southeast-1, us-west-2)
Default: ap-southeast-1
NetprobeInstallDirectory:
Type: String
Description: Directory where Netprobe will be installed
Default: "~/geneos"
S3NetprobeURL:
Type: String
Description: S3 URL to the Netprobe tar.gz file
S3NetprobeSetupURL:
Type: String
Description: S3 URL to the Netprobe setup XML file
Rules:
RequireS3NetprobeURL:
Assertions:
- Assert: !Not [!Equals [!Ref S3NetprobeURL, ""]]
AssertDescription: S3NetprobeURL must not be empty
RequireS3NetprobeSetupURL:
Assertions:
- Assert: !Not [!Equals [!Ref S3NetprobeSetupURL, ""]]
AssertDescription: S3NetprobeSetupURL must not be empty
Resources:
NetprobeInstallationDocument:
Type: AWS::SSM::Document
Properties:
DocumentType: Command
DocumentFormat: YAML
Content:
schemaVersion: '2.2'
description: Install and configure Netprobe on existing EC2 instances
parameters:
AWSRegion:
type: String
description: AWS Region
NetprobeInstallDirectory:
type: String
description: Netprobe installation directory
S3NetprobeURL:
type: String
description: S3 URL to Netprobe package
S3NetprobeSetupURL:
type: String
description: S3 URL to setup file
mainSteps:
- action: aws:runShellScript
name: installNetprobe
inputs:
timeoutSeconds: '3600'
runCommand:
- |
#!/bin/bash
set -e
echo "=== Starting Netprobe Installation ==="
# Identify OS and version
echo "--- Identifying OS and version ---"
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
VERSION_ID=$VERSION_ID
elif [ -f /etc/redhat-release ]; then
OS=$(awk '{print tolower($1)}' /etc/redhat-release)
VERSION_ID=$(awk '{print $3}' /etc/redhat-release)
else
echo "ERROR: Unsupported OS"
exit 1
fi
echo "Detected OS: $OS $VERSION_ID"
# Detect default user
if [ "$OS" = "ubuntu" ]; then
DEFAULT_USER="ubuntu"
else
DEFAULT_USER="ec2-user"
fi
echo "Default user: $DEFAULT_USER"
# Check if SSM agent user exists, fallback to detected user
if id "ssm-user" &>/dev/null; then
INSTALL_USER="ssm-user"
else
INSTALL_USER="$DEFAULT_USER"
fi
echo "Installation user: $INSTALL_USER"
# Set default values for optional parameters if they're empty
AWS_REGION="{{AWSRegion}}"
if [ -z "$AWS_REGION" ]; then
AWS_REGION="ap-southeast-1"
fi
export AWS_DEFAULT_REGION="$AWS_REGION"
# Parse the netprobe install directory (handle ~ expansion)
NETPROBE_DIR="{{NetprobeInstallDirectory}}"
if [ -z "$NETPROBE_DIR" ]; then
NETPROBE_DIR="~/geneos"
fi
if [[ "$NETPROBE_DIR" == ~* ]]; then
NETPROBE_DIR=${NETPROBE_DIR:1}
NETPROBE_DIR="/home/$INSTALL_USER$NETPROBE_DIR"
fi
# Pre-update checks and backup of existing installation
echo "--- Verifying existing netprobe directory and stopping service ---"
if [ ! -d "$NETPROBE_DIR/netprobe" ]; then
echo "ERROR: Expected directory '$NETPROBE_DIR/netprobe' not found. Aborting update."
exit 1
fi
# Stop netprobe service
sudo systemctl stop netprobe.service || true
# Create backup directory and archive current netprobe
echo "--- Backing up current netprobe directory ---"
sudo mkdir -p "$NETPROBE_DIR/backup/netprobe"
BACKUP_TS=$(date +%Y%m%d%H%M%S)
sudo tar -czf "$NETPROBE_DIR/backup/netprobe/netprobe-$BACKUP_TS.tar.gz" -C "$NETPROBE_DIR" netprobe
# Delete current netprobe directory
echo "--- Removing existing netprobe directory ---"
sudo rm -rf "$NETPROBE_DIR/netprobe"
# Download and extract Netprobe
echo "--- Downloading Netprobe ---"
aws s3 cp "{{S3NetprobeURL}}" "$NETPROBE_DIR/netprobe.tar.gz"
if [ ! -f "$NETPROBE_DIR/netprobe.tar.gz" ]; then
echo "ERROR: Failed to download Netprobe package"
exit 1
fi
cd "$NETPROBE_DIR"
tar -xzf netprobe.tar.gz
sudo chown -R $INSTALL_USER:$INSTALL_USER "$NETPROBE_DIR/"
# Download setup file
echo "--- Downloading Netprobe setup file ---"
aws s3 cp "{{S3NetprobeSetupURL}}" "$NETPROBE_DIR/netprobe/netprobe.setup.xml"
if [ ! -f "$NETPROBE_DIR/netprobe/netprobe.setup.xml" ]; then
echo "ERROR: Failed to download setup file"
exit 1
fi
# Enable and start netprobe service
sudo systemctl daemon-reload
sudo systemctl enable netprobe.service
sudo systemctl restart netprobe.service
# Wait a few seconds and check service status
sleep 3
if sudo systemctl is-active --quiet netprobe.service; then
echo "SUCCESS: Netprobe service started successfully"
else
echo "WARNING: Netprobe service failed to start"
sudo systemctl status netprobe.service
fi
echo "=== Netprobe Installation Complete ==="
NetprobeInstallationByInstanceIds:
Type: AWS::SSM::Association
Properties:
Name: !Ref NetprobeInstallationDocument
Targets:
- Key: InstanceIds
Values: !Ref InstanceIds
Parameters:
AWSRegion:
- !Ref AWSRegion
NetprobeInstallDirectory:
- !Ref NetprobeInstallDirectory
S3NetprobeURL:
- !Ref S3NetprobeURL
S3NetprobeSetupURL:
- !Ref S3NetprobeSetupURL
Outputs:
SSMDocumentName:
Description: Name of the SSM Document created for Netprobe installation
Value: !Ref NetprobeInstallationDocument
Export:
Name: !Sub "${AWS::StackName}-SSMDocument"
AssociationId:
Description: SSM Association ID for the Netprobe installation
Value: !Ref NetprobeInstallationByInstanceIds
Export:
Name: !Sub "${AWS::StackName}-AssociationId"
["Geneos"]
["Geneos > Netprobe"]
["User Guide"]