-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
Β·136 lines (121 loc) Β· 3.63 KB
/
deploy.sh
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env bash
# Print cool logo for the script
echo "π Bookstack Docker automation tool 1.0v π"
echo "-----------------------------------------"
echo -e "π Developed by: Antonio Gagliarducci π"
echo "-----------------------------------------"
# Function to check if Docker is installed
check_docker_installed() {
if ! command -v docker &> /dev/null; then
echo "Error: Docker is not installed."
exit 1
fi
}
# Function to start the services
start_service() {
docker compose up -d || { echo "Error: Failed to start the service."; exit 1; }
}
# Function to stop the services
stop_service() {
docker compose down || { echo "Error: Failed to stop the service."; exit 1; }
}
# Function to show logs of all containers
show_logs() {
docker compose logs
}
# Function to show logs of a specific container
show_container_logs() {
docker logs "$1"
}
# Function to update and restart the services
update_service() {
(docker compose pull && docker compose up -d) || { echo "Error: Failed to update and restart."; exit 1; }
}
# Function to restart the services
restart_service() {
docker compose restart || { echo "Error: Failed to restart the service."; exit 1; }
}
# Function to show the status of the services
show_service_status() {
docker compose ps
}
# Function to enter inside a container
enter_container() {
container_name="$1"
case "$container_name" in
caddy | bookstack | bookstack_db)
docker exec -it "$container_name" sh
;;
*)
echo "Error: Invalid container name '$container_name'. Available β‘οΈ (caddy, bookstack, bookstack_db)"
exit 1
;;
esac
}
# Function to show the help page
show_help() {
echo "Usage: $0 {start|stop|logs|logs_caddy|logs_bookstack|logs_bookstack_db|update|restart|status|enter}"
echo "Description:"
echo " start - Start the Docker Compose service"
echo " stop - Stop the Docker Compose service"
echo " logs - Show logs of all containers"
echo " logs_caddy - Show logs of the Caddy container"
echo " logs_bookstack - Show logs of the Bookstack container"
echo " logs_bookstack_db - Show logs of the Bookstack DB container"
echo " update - Update all containers and restart"
echo " restart - Restart the Docker Compose service"
echo " status - Show status of the Docker Compose service"
echo " enter <container_name> - Enter inside a container [caddy|bookstack|bookstack_db]"
echo " help - Show this help message"
}
# Main script
check_docker_installed
# Handle command line arguments
case "$1" in
start)
start_service
;;
stop)
stop_service
;;
logs)
show_logs
;;
logs_caddy)
show_container_logs caddy
;;
logs_bookstack)
show_container_logs bookstack
;;
logs_bookstack_db)
show_container_logs bookstack_db
;;
update)
update_service
;;
restart)
restart_service
;;
status)
show_service_status
;;
enter)
if [ -z "$2" ]; then
echo "Error: Please specify a container name."
exit 1
fi
enter_container "$2"
;;
help)
show_help
;;
*)
echo -e "Invalid option! See below: \n"
show_help
exit 1
;;
esac
echo "-----------------------------------------"
# Exit successfully
echo -e "πππ¨ End of the script!\nHave a good day :)"
exit 0