Skip to content

Commit 5cd4a79

Browse files
pudkrongcoderbyheart
authored andcommitted
feat: health-check script to check bridge connection
1 parent 11a7abd commit 5cd4a79

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

cdk/resources/Integration.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Duration,
23
aws_ec2 as EC2,
34
aws_ecr as ECR,
45
aws_ecs as ECS,
@@ -193,7 +194,7 @@ export class Integration extends Construct {
193194
MOSQUITTO__BRIDGE01__BRIDGE_KEYFILE: `/mosquitto/security/nrfcloud_client.key`,
194195
MOSQUITTO__BRIDGE01__BRIDGE_INSECURE: `false`,
195196
MOSQUITTO__BRIDGE01__START_TYPE: `automatic`,
196-
MOSQUITTO__BRIDGE01__KEEPALIVE_INTERVAL: `10`,
197+
MOSQUITTO__BRIDGE01__KEEPALIVE_INTERVAL: `30`,
197198
MOSQUITTO__BRIDGE01__NOTIFICATIONS: `true`,
198199
MOSQUITTO__BRIDGE01__NOTIFICATIONS_LOCAL_ONLY: `true`,
199200
MOSQUITTO__BRIDGE01__CLEANSESSION: `true`,
@@ -211,9 +212,10 @@ export class Integration extends Construct {
211212
MOSQUITTO__BRIDGE02__BRIDGE_CERTFILE: `/mosquitto/security/iot.crt`,
212213
MOSQUITTO__BRIDGE02__BRIDGE_KEYFILE: `/mosquitto/security/iot.key`,
213214
MOSQUITTO__BRIDGE02__BRIDGE_INSECURE: `false`,
215+
MOSQUITTO__BRIDGE02__BRIDGE_TRY_PRIVATE: `true`,
214216
MOSQUITTO__BRIDGE02__LOCAL_CLIENTID: `iot-bridge-local`,
215217
MOSQUITTO__BRIDGE02__START_TYPE: `automatic`,
216-
MOSQUITTO__BRIDGE02__KEEPALIVE_INTERVAL: `10`,
218+
MOSQUITTO__BRIDGE02__KEEPALIVE_INTERVAL: `30`,
217219
MOSQUITTO__BRIDGE02__NOTIFICATIONS: `true`,
218220
MOSQUITTO__BRIDGE02__NOTIFICATIONS_LOCAL_ONLY: `true`,
219221
MOSQUITTO__BRIDGE02__CLEANSESSION: `true`,
@@ -257,10 +259,11 @@ export class Integration extends Construct {
257259
},
258260
environment,
259261
healthCheck: {
260-
command: [
261-
'CMD-SHELL',
262-
'mosquitto_sub -p 1883 -t topic -C 1 -E -i probe -W 3',
263-
],
262+
command: ['CMD-SHELL', '/health.sh'],
263+
interval: Duration.minutes(1),
264+
retries: 3,
265+
startPeriod: Duration.minutes(3),
266+
timeout: Duration.seconds(5),
264267
},
265268
})
266269

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
results=$(mosquitto_sub -p 1883 -t "\$SYS/broker/connection/#" -i health-check -C 2 -W 3 2>/dev/null)
4+
expected_results="1"$'\n'"1"
5+
6+
if [[ "$results" == "$expected_results" ]]; then
7+
echo "Both commands were successful."
8+
else
9+
echo "One or both commands failed."
10+
exit 1
11+
fi

0 commit comments

Comments
 (0)