Skip to content

Commit 9decf24

Browse files
authored
fix - update hacker-news-headlines.gpt
Enable re-running by checking for the mongodb container and either starting it or running it. Signed-off-by: DJ Carpenter <[email protected]>
1 parent 73e994f commit 9decf24

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

examples/hacker-news-headlines.gpt

+18-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,24 @@ description: starts a MongoDB database
1616

1717
#!/usr/bin/env bash
1818

19-
docker run --rm -d -p 27017:27017 --name mongodb mongo:latest
19+
# The name of your container
20+
CONTAINER_NAME=mongodb
21+
22+
# Check if the container already exists
23+
if docker ps -a --format '{{.Names}}' | grep -Eq "^${CONTAINER_NAME}\$"; then
24+
echo "Container ${CONTAINER_NAME} exists."
25+
26+
# Check if the container is already running
27+
if ! docker ps --format '{{.Names}}' | grep -Eq "^${CONTAINER_NAME}\$"; then
28+
echo "Starting existing container ${CONTAINER_NAME}."
29+
docker start ${CONTAINER_NAME}
30+
else
31+
echo "Container ${CONTAINER_NAME} is already running."
32+
fi
33+
else
34+
echo "Container ${CONTAINER_NAME} does not exist. Running a new one."
35+
docker run --rm -d -p 27017:27017 --name ${CONTAINER_NAME} mongo:latest
36+
fi
2037

2138
---
2239
name: mongo_command

0 commit comments

Comments
 (0)