Repository navigation
Expand file tree
/
Copy pathmain.sh
More file actions
executable file
·80 lines (63 loc) · 2.58 KB
/
Copy pathmain.sh
File metadata and controls
executable file
·80 lines (63 loc) · 2.58 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
#!/usr/bin/env bash
#Variables
source ./config.sh
source ./logging.sh
write_log "----SCRIPT STARTED----"
write_log "Docker home directory is $DOCKER_HOME"
write_log "Use SSH key is set to $USE_KEY"
################################################################################## Stop all containers
write_log "Stopping all containers..."
if docker stop $(docker ps -a -q) ; then
write_log "Successfully all running containers"
else
write_error "Issues were encountered while stopping containers, exiting: 1"
exit 1 #exit if there were issues stopping containers
fi
write_log "All containers stopped successfully"
################################################################################## Create archive locally
write_log "Creating archive..."
ARCHIVE_NAME="$LOCAL_HOST-archive-$DATE.zip"
if zip -r -v "./$ARCHIVE_NAME" $DOCKER_HOME ; then
write_log "Successfully created archive"
else
write_error "Issues were encountered while creating archive"
fi
################################################################################## Export Archive
write_log "Copying archive to remote repo..."
if [ $USE_KEY = true ]; then
write_log "Using ssh key $SSH_KEY"
if [ -f $SSH_KEY ]; then #check if file exists
if scp -i $SSH_KEY "$ARCHIVE_NAME" "$REMOTE_REPO" ; then
write_log "Done"
else
write_error "Issues were encountered while copying archive to remote repo"
fi
else
write_error "Could not find key file $SSH_KEY" #error out if file does not exist
fi
else
write_log "Using SSH password"
if sshpass -p $PASSWORD scp "$ARCHIVE_NAME" "$REMOTE_REPO" ; then
write_log "Done"
else
write_error "Issues were encountered while copying archive to remote repo"
fi
fi
################################################################################## Delete local Archive
write_log "Deleting local archive file..."
if rm -f $ARCHIVE_NAME ; then
write_log "Done"
else
write_error "Issues were encountered while deleting local archive $ARCHIVE_NAME"
fi
################################################################################## Start uncommented containers
write_log "Starting stopped containers..."
for file in $(cat ./compose-files.txt | egrep -v "#" ); do
if docker compose -f $file up -d ; then
write_log "Successfully started $file"
else
write_error "Issues were encountered starting $file"
fi
done
write_log "All containers specified started successfully. If any didn't, check your compose-files.txt file."
write_log "----SCRIPT FINISHED----"