-
Notifications
You must be signed in to change notification settings - Fork 5
/
controller
executable file
·98 lines (82 loc) · 2.96 KB
/
controller
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
#! /bin/bash
#
# Usage:
# controller (create_volumes|backup_db|start|stop)
#
# Starts or stops all of the containers.
cfg=config.inc
set -e
if [[ "$OSTYPE" == "darwin"* ]]
then
readonly ExecName=$(greadlink -f "$0")
else
readonly ExecName=$(readlink --canonicalize "$0")
fi
main()
{
local baseDir=$(dirname "$ExecName")
if [ "$#" -lt 1 ]
then
printf 'Requires "create_volumes", "backup_db", "start" or "stop" as its second parameter.\n' >&2
return 1
fi
local action="$1"
. "$baseDir/$cfg"
case "$action" in
create_volumes)
mkdir -p "$LOCAL_IRODS_VOLUME_PATH"
docker volume create --driver local \
--opt type=none \
--opt device="$LOCAL_IRODS_VOLUME_PATH" \
--opt o=bind "$DOCKER_IRODS_VOLUME"
mkdir -p "$LOCAL_DB_VOLUME_PATH"
docker volume create --driver local \
--opt type=none \
--opt device="$LOCAL_DB_VOLUME_PATH" \
--opt o=bind "$DOCKER_DB_VOLUME"
mkdir -p "$LOCAL_DB_BACKUP_VOLUME_PATH"
docker volume create --driver local \
--opt type=none \
--opt device="$LOCAL_DB_BACKUP_VOLUME_PATH" \
--opt o=bind "$DOCKER_DB_BACKUP_VOLUME"
mkdir -p "$LOCAL_SFTPGO_VOLUME_PATH"
docker volume create --driver local \
--opt type=none \
--opt device="$LOCAL_SFTPGO_VOLUME_PATH" \
--opt o=bind "$DOCKER_SFTPGO_VOLUME"
;;
backup_db)
local db_backup_dir=/var/opt/db_backup
local db_backup_file=pg_backup_`date +"%Y%m%d%H%M"`.sql
if ! command -v docker-compose > /dev/null; then
docker compose --file "$baseDir"/docker-compose.yml --project-name "$ENV_NAME" exec -e PGPASSWORD="$DB_PASSWORD" dbms pg_dump -U "$DB_USER" -d "$DB_NAME" -F p -f "$db_backup_dir/$db_backup_file"
else
docker-compose --file "$baseDir"/docker-compose.yml --project-name "$ENV_NAME" exec -e PGPASSWORD="$DB_PASSWORD" dbms pg_dump -U "$DB_USER" -d "$DB_NAME" -F p -f "$db_backup_dir/$db_backup_file"
fi
if test -f "$LOCAL_DB_BACKUP_VOLUME_PATH/$db_backup_file"; then
printf 'Created a DB backup file - "%s"\n' "$LOCAL_DB_BACKUP_VOLUME_PATH/$db_backup_file"
else
printf 'Failed to created a DB backup file - "%s"\n' "$LOCAL_DB_BACKUP_VOLUME_PATH/$db_backup_file" >&2
fi
;;
start)
if ! command -v docker-compose > /dev/null; then
docker compose --file "$baseDir"/docker-compose.yml --project-name "$ENV_NAME" up -d
else
docker-compose --file "$baseDir"/docker-compose.yml --project-name "$ENV_NAME" up -d
fi
;;
stop)
if ! command -v docker-compose > /dev/null; then
docker compose --file "$baseDir"/docker-compose.yml --project-name "$ENV_NAME" down --remove-orphans
else
docker-compose --file "$baseDir"/docker-compose.yml --project-name "$ENV_NAME" down --remove-orphans
fi
;;
*)
printf 'Unknown command "%s"\n' "$action" >&2
return 1
;;
esac
}
main "$@"