Skip to content

Commit e05afc1

Browse files
Merge pull request #202 from ByteInternet/brancher-cleanup-script
2 parents cc438f9 + bf658cb commit e05afc1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/hypernode-platform/tools/hypernode-brancher.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,31 @@ Brancher App 'example-eph123456' deleted. See hypernode-systemctl brancher --lis
225225
Brancher App 'example-eph234567' deleted. See hypernode-systemctl brancher --list for the list of remaining brancher apps.
226226
```
227227

228+
##### Example cleanup script
229+
230+
To prevent long running Hypernode Brancher nodes from accumulating, you can use the following script to clean up old Brancher nodes. This is configured to delete all Brancher nodes that have been running for more than 4 hours:
231+
232+
```bash
233+
MAX_MINUTES_ALIVE=240
234+
LONG_RUNNING_BRANCHERS=$(hypernode-systemctl brancher --list --machine-readable | jq -r '.[] | select (.minutes>='"${MAX_MINUTES_ALIVE}"') | .name')
235+
236+
if [ -z "${LONG_RUNNING_BRANCHERS}" ]; then
237+
echo "No long running Brancher nodes found"
238+
exit 0
239+
fi
240+
241+
for BRANCHER in ${LONG_RUNNING_BRANCHERS}; do
242+
echo "Deleting Brancher node ${BRANCHER}"
243+
hypernode-systemctl brancher --delete "${BRANCHER}"
244+
done
245+
```
246+
247+
You can convert this to a single line if you're into that:
248+
249+
```bash
250+
hypernode-systemctl brancher --list --machine-readable | jq -r '.[] | select (.minutes>=240) | .name' | xargs -n1 --no-run-if-empty hypernode-systemctl brancher --delete
251+
```
252+
228253
## Brancher Install Hook
229254

230255
While it's already very valuable to be able to create a running copy of your Hypernode, it is a very common use case to make some configuration changes.

0 commit comments

Comments
 (0)