-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdocker_entrypoint.sh
executable file
·127 lines (102 loc) · 2.43 KB
/
docker_entrypoint.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
#!/bin/bash
set -Eeo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
function print() {
echo -e "$(date +"%F %T") [Entrypoint] $*"
}
function quit() {
./seafile-server-latest/seahub.sh stop
./seafile-server-latest/seafile.sh stop
exit
}
function timezoneAdjustment() {
if [ "$TZ" ]
then
if [ ! -f "/usr/share/zoneinfo/$TZ" ]
then
print "Invalid timezone $TZ"
else
ln -sf "/usr/share/zoneinfo/$TZ" /etc/localtime
print "Local time set to $TZ"
fi
fi
}
function rightsManagement() {
print "Checking permissions"
if [ "$PUID" == "" ]
then
print "PUID not set, using current"
PUID=$(id -u seafile)
fi
if [ "$PGID" == "" ]
then
print "GUID not set, using current"
PGID=$(id -g seafile)
fi
print "Adjusting identifiers"
groupmod -g "$PGID" seafile
usermod -u "$PUID" seafile
dirs=("/shared/conf" "/shared/logs" "/shared/media" "/shared/seafile-data" "/shared/seahub-data" "/shared/sqlite")
for dir in "${dirs[@]}"
do
if [[ -d "$dir" && ("$(stat -c %u "$dir")" != "$PUID" || "$(stat -c %g "$dir")" != "$PGID") ]]
then
print "Changing owner for $dir"
chown -R seafile:seafile "$dir"
fi
done
}
function init() {
if [ ! -f "/shared/conf/ccnet.conf" ]
then
print "No config found. Running init script"
su seafile -pPc "/home/seafile/init.sh"
if [ $? != 0 ]
then
print "${RED}Init failed${NC}"
exit 1
fi
fi
}
function launch() {
init
/home/seafile/bind_volume.sh
print "Running launch script"
su seafile -pc "/home/seafile/launch.sh"
if [ $? != 0 ]
then
print "${RED}Launch failed${NC}"
exit 1
fi
print "Waiting for termination"
tail -f /dev/null & wait
}
function gc() {
/home/seafile/bind_volume.sh
print "Running garbage collection"
/opt/seafile/seafile-server-latest/seaf-gc.sh $@
if [[ $? -ne 0 ]]; then
print "${RED}Failed${NC}"
exit 1
else
print "${GREEN}Success${NC}"
fi
}
# Quit when receiving some signals
trap quit SIGTERM
trap quit SIGINT
timezoneAdjustment
rightsManagement
if [ ! -d "/shared" ]
then
mkdir /shared
fi
chown seafile:seafile /shared
case "$1" in
launch) launch;;
gc) gc ${@:2};;
shell) su seafile;;
*) $1;;
esac