Skip to content

Commit

Permalink
reboot device and pause camera utility scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunderl committed Oct 17, 2022
1 parent 1de445d commit 97a4497
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 18 deletions.
47 changes: 46 additions & 1 deletion util-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ Check a device for software updates.
A new version is available for device device-ulagxmplffb3zwkgltmkj43lyq: 4.3.55
(current version: 4.3.45)

## reboot-device.sh

Reboot a device.

$ ./reboot-device.sh
Getting devices...
0: device-53amxmplyn3gmj72epzanacniy my-se70-1
1: device-6talxmpl5mmik6qh5moba6jium my-manh-24
Choose a device
1
Reboot device device-6talxmpl5mmik6qh5moba6jium? (y/n)y
{
"Jobs": [
{
"DeviceId": "device-6talxmpl5mmik6qh5moba6jium",
"JobId": "device-6talxmpl5mmik6qh5moba6jium-8"
}
]
}

## register-camera.sh

Register a camera.
Expand Down Expand Up @@ -55,7 +75,32 @@ Delete a camera node.

# Application scripts

Copy these scripts into a sample app directory, or an application adapted from a sample app.
Run these scripts from a sample app directory, or an application adapted from a sample app.

## pause-camera.sh

Pause or resume a camera stream. You can specify the camera stream or choose it interactively.

$ ./pause-camera.sh <application-instance-id> <stream-name> <PAUSE|RESUME>

From an application directory (with `application-id.txt` file present). If you choose a node
that's paused, the script resumes instead of pausing.

my-app$ ./pause-camera.sh

Getting nodes...
0: SAMPLE_CODE RUNNING
1: warehouse-floor RUNNING
2: hdmi_data_sink RUNNING
3: entrance-north PAUSED
4: SQUEEZENET_PYTORCH RUNNING
Choose a node
1
Signalling node warehouse-floor
+ aws panorama signal-application-instance-node-instances --application-instance-id applicationInstance-r3a7xmplcbmpjqeds7vj4b6pjy --node-signals '[{"NodeInstanceId": "warehouse-floor", "Signal": "PAUSE"}]'
{
"ApplicationInstanceId": "applicationInstance-r3a7xmplcbmpjqeds7vj4b6pjy"
}

## push.sh

Expand Down
23 changes: 16 additions & 7 deletions util-scripts/check-updates.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash
#!/usr/bin/env bash
set -eo pipefail
if [[ $# -eq 1 ]] ; then
DEVICE_ID=${1}
else

hash jq 2>/dev/null || {
echo >&2 "This script uses jq. Download at https://stedolan.github.io/jq/"
exit 1
}

choose_device() {
echo "Getting devices..."
DEVICES=$(aws panorama list-devices)
DEVICE_NAMES=($((echo ${DEVICES} | jq -r '.Devices |=sort_by(.LastUpdatedTime) | [.Devices[].Name] | @sh') | tr -d \'\"))
Expand All @@ -18,9 +22,8 @@ else
done
echo "Choose a device"
read D_INDEX
echo "Deploying to device ${DEVICE_IDS[${D_INDEX}]}"
DEVICE_ID=${DEVICE_IDS[${D_INDEX}]}
fi
}

version_is_newer() {
NEW_VERSION=$1
Expand Down Expand Up @@ -54,7 +57,13 @@ apply_update() {
aws panorama create-job-for-devices --device-ids ${DEVICE_ID} --device-job-config "${CONFIG}" --job-type OTA
}

echo "Checking for updates."
if [[ $# -eq 1 ]] ; then
DEVICE_ID=${1}
else
choose_device
fi

echo "Checking ${DEVICE_ID} for updates."
DEVICE=$(aws panorama describe-device --device-id ${DEVICE_ID})

OLD_VERSION=$(echo $DEVICE | jq -r .CurrentSoftware)
Expand Down
2 changes: 1 addition & 1 deletion util-scripts/cleanup-patches.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -eo pipefail
# Deregisters old application package versions. Each patch version corresponds to a package manifest
# in an Amazon S3 access point managed by AWS Panorama. Deletes the manifest file, but not binary
Expand Down
2 changes: 1 addition & 1 deletion util-scripts/deregister-camera.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -eo pipefail
if [[ $# -eq 1 ]] ; then
NAME=$1
Expand Down
57 changes: 57 additions & 0 deletions util-scripts/pause-camera.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
set -eo pipefail

hash jq 2>/dev/null || {
echo >&2 "This script uses jq. Download at https://stedolan.github.io/jq/"
exit 1
}

choose_camera() {
echo "Getting nodes..."
INSTANCE_ID=$1
DEVICES=$(aws panorama list-application-instance-node-instances --application-instance-id $INSTANCE_ID)
NODE_NAMES=($((echo ${DEVICES} | jq -r '[.NodeInstances[].PackageName] | @sh') | tr -d \'\"))
NODE_STATUSES=($((echo ${DEVICES} | jq -r '[.NodeInstances[].CurrentStatus] | @sh') | tr -d \'\"))
if [ -x ${NODE_NAMES} ]; then
echo "No nodes found for application instance $INSTANCE_ID."
exit
fi
for (( c=0; c<${#NODE_NAMES[@]}; c++ ))
do
printf "%s: %-24s %s\n" "${c}" "${NODE_NAMES[${c}]}" "${NODE_STATUSES[${c}]}"
done
echo "Choose a node"
read D_INDEX
echo "Signalling node ${NODE_NAMES[${D_INDEX}]}"
COMMAND=PAUSE
if [[ ${NODE_STATUSES[${D_INDEX}]} =~ "PAUSED" ]]; then
COMMAND=RESUME
fi
CAMERA=${NODE_NAMES[${D_INDEX}]}
}

print_usage() {
echo "Usage: ./pause-camera.sh (with application-id.txt in folder)"
echo "Usage: ./pause-camera.sh <application-instance> <stream-name> <PAUSE|RESUME>"
exit 1
}

if [[ $# -eq 3 ]] ; then
APPLICATION_ID=$1
CAMERA=$2
COMMAND=$3
elif [[ $# -eq 0 ]] ; then
if [ -f "application-id.txt" ]; then
APPLICATION_ID=$(cat application-id.txt)
choose_camera $APPLICATION_ID
else
print_usage
fi
else
print_usage
fi
SIGNAL='[{"NodeInstanceId": "MY_CAMERA", "Signal": "MY_COMMAND"}]'
SIGNAL=${SIGNAL/MY_CAMERA/$CAMERA}
SIGNAL=${SIGNAL/MY_COMMAND/$COMMAND}
set -x
aws panorama signal-application-instance-node-instances --application-instance-id ${APPLICATION_ID} --node-signals "${SIGNAL}"
2 changes: 1 addition & 1 deletion util-scripts/provision-device.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -eo pipefail
if [[ $# -eq 1 ]] ; then
DEVICE_NAME=$1
Expand Down
2 changes: 1 addition & 1 deletion util-scripts/push.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -eo pipefail
if [[ $# -eq 1 ]] ; then
if [[ $1 == "deploy" ]] ; then
Expand Down
40 changes: 40 additions & 0 deletions util-scripts/reboot-device.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -eo pipefail

hash jq 2>/dev/null || {
echo >&2 "This script uses jq. Download at https://stedolan.github.io/jq/"
exit 1
}

choose_device() {
echo "Getting devices..."
DEVICES=$(aws panorama list-devices)
DEVICE_NAMES=($((echo ${DEVICES} | jq -r '.Devices |=sort_by(.LastUpdatedTime) | [.Devices[].Name] | @sh') | tr -d \'\"))
DEVICE_IDS=($((echo ${DEVICES} | jq -r '.Devices |=sort_by(.LastUpdatedTime) | [.Devices[].DeviceId] | @sh') | tr -d \'\"))
if [ -x ${DEVICE_IDS} ]; then
echo "No devices found. Provision a device with the management console or"
echo "use the provision-device.sh script under util-scripts/ in this repository."
exit
fi
for (( c=0; c<${#DEVICE_NAMES[@]}; c++ ))
do
echo "${c}: ${DEVICE_IDS[${c}]} ${DEVICE_NAMES[${c}]}"
done
echo "Choose a device"
read D_INDEX
DEVICE_ID=${DEVICE_IDS[${D_INDEX}]}
}

if [[ $# -eq 1 ]] ; then
DEVICE_ID=${1}
else
choose_device
fi
while true; do
read -p "Reboot device $DEVICE_ID? (y/n)" response
case $response in
[Yy]* ) aws panorama create-job-for-devices --device-ids ${DEVICE_ID} --job-type REBOOT; break;;
[Nn]* ) exit;;
* ) echo "Response must start with y or n.";;
esac
done
2 changes: 1 addition & 1 deletion util-scripts/register-camera.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -eo pipefail
if [[ $# -eq 3 ]] ; then
NAME=$1
Expand Down
2 changes: 1 addition & 1 deletion util-scripts/rename-package.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -eo pipefail
if [[ $# -eq 2 ]] ; then
OLD=$1
Expand Down
2 changes: 1 addition & 1 deletion util-scripts/samplify.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -eo pipefail
CODE_PACKAGE=SAMPLE_CODE
MODEL_PACKAGE=SQUEEZENET_PYTORCH
Expand Down
2 changes: 1 addition & 1 deletion util-scripts/update-model-config.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -eo pipefail
MODEL_ASSET=fd1aef48acc3350a5c2673adacffab06af54c3f14da6fe4a8be24cac687a386e
MODEL_PACKAGE=SQUEEZENET_PYTORCH
Expand Down
10 changes: 8 additions & 2 deletions util-scripts/view-logs.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash
# device id
#!/usr/bin/env bash
set -eo pipefail

hash jq 2>/dev/null || {
echo >&2 "This script uses jq. Download at https://stedolan.github.io/jq/"
exit 1
}

if [[ $# -eq 2 ]] ; then
DEVICE_ID=$1
APPLICATION_ID=$2
Expand Down

0 comments on commit 97a4497

Please sign in to comment.