-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer.sh
More file actions
executable file
·120 lines (104 loc) · 2.43 KB
/
container.sh
File metadata and controls
executable file
·120 lines (104 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
# Basic settings
NAME="redaction-service"
PORT=3000
# Check if container exists
check_exists() {
podman container exists "$NAME"
}
# Check if container is running
check_running() {
podman container inspect "$NAME" >/dev/null 2>&1 && \
podman container inspect -f '{{.State.Running}}' "$NAME" | grep -q "true"
}
# Build the container
build() {
echo "Building container..."
podman build -t "$NAME" .
}
# Start the service
start() {
# If already running, do nothing
if check_running; then
echo "Service is already running"
return
fi
# If container exists but not running, start it
if check_exists; then
echo "Starting existing container..."
podman start "$NAME"
else
echo "Creating new container..."
podman run -d \
--name "$NAME" \
-p "$PORT:$PORT" \
--security-opt label=disable \
"$NAME"
fi
echo "Service is running at http://localhost:$PORT"
}
# Stop the service
stop() {
if check_running; then
echo "Stopping service..."
podman stop "$NAME"
else
echo "Service is not running"
fi
}
# Show logs
logs() {
if check_exists; then
podman logs -f "$NAME"
else
echo "No logs found - service hasn't been started yet"
fi
}
# Remove everything
clean() {
if check_running; then
echo "Stopping service..."
podman stop "$NAME"
fi
if check_exists; then
echo "Removing container..."
podman rm "$NAME"
fi
echo "Removing image..."
podman rmi "$NAME"
}
# Show status
status() {
if ! check_exists; then
echo "Service hasn't been created yet"
return
fi
if check_running; then
echo "Service is running"
else
echo "Service is stopped"
fi
}
# Show help if no command given
if [ $# -eq 0 ]; then
echo "Usage: $0 <command>"
echo "Commands:"
echo " build - Build the container"
echo " start - Start the service"
echo " stop - Stop the service"
echo " logs - Show logs"
echo " clean - Remove container and image"
echo " status - Show service status"
exit 1
fi
# Run the command
case "$1" in
build|start|stop|logs|clean|status)
$1
;;
*)
echo "Unknown command: $1"
echo "Try: build, start, stop, logs, clean, or status"
exit 1
;;
esac