forked from rustfs/rustfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·137 lines (122 loc) · 4.32 KB
/
entrypoint.sh
File metadata and controls
executable file
·137 lines (122 loc) · 4.32 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/sh
set -e
# 1) Normalize command:
# - No arguments: default to execute rustfs with DATA_VOLUMES
# - First argument starts with '-': treat as rustfs arguments, auto-prefix rustfs
# - First argument is 'rustfs': replace with absolute path to avoid PATH interference
# - Otherwise: treat as full rustfs arguments (e.g., /data paths)
if [ $# -eq 0 ]; then
set -- /usr/bin/rustfs
elif [ "${1#-}" != "$1" ]; then
set -- /usr/bin/rustfs "$@"
elif [ "$1" = "rustfs" ]; then
shift
set -- /usr/bin/rustfs "$@"
elif [ "$1" = "/usr/bin/rustfs" ]; then
: # already normalized
elif [ "$1" = "cargo" ]; then
: # Pass through cargo command as-is
else
set -- /usr/bin/rustfs "$@"
fi
# 2) Process data volumes (separate from log directory)
DATA_VOLUMES=""
process_data_volumes() {
VOLUME_RAW="${RUSTFS_VOLUMES:-/data}"
# Convert comma/tab to space
VOLUME_LIST_RAW=$(echo "$VOLUME_RAW" | tr ',\t' ' ')
VOLUME_LIST=""
for vol in $VOLUME_LIST_RAW; do
# Helper to manually expand {N..M} since sh doesn't support it on variables
if echo "$vol" | grep -E -q "\{[0-9]+\.\.[0-9]+\}"; then
PREFIX=${vol%%\{*}
SUFFIX=${vol##*\}}
RANGE=${vol#*\{}
RANGE=${RANGE%\}}
START=${RANGE%%..*}
END=${RANGE##*..}
# Check if START and END are numbers
if [ "$START" -eq "$START" ] 2>/dev/null && [ "$END" -eq "$END" 2>/dev/null ]; then
i=$START
while [ "$i" -le "$END" ]; do
VOLUME_LIST="$VOLUME_LIST ${PREFIX}${i}${SUFFIX}"
i=$((i+1))
done
else
# Fallback if not numbers
VOLUME_LIST="$VOLUME_LIST $vol"
fi
else
VOLUME_LIST="$VOLUME_LIST $vol"
fi
done
for vol in $VOLUME_LIST; do
case "$vol" in
/*) DATA_VOLUMES="$DATA_VOLUMES $vol" ;;
*) : ;; # skip non-absolute paths (including http(s):// URLs)
esac
done
echo "Initializing data directories:$DATA_VOLUMES"
for vol in $DATA_VOLUMES; do
if [ ! -d "$vol" ]; then
echo " mkdir -p $vol"
mkdir -p "$vol"
# If target user is specified, try to set directory owner to that user (non-recursive to avoid large disk overhead)
if [ -n "$RUSTFS_UID" ] && [ -n "$RUSTFS_GID" ]; then
chown "$RUSTFS_UID:$RUSTFS_GID" "$vol" 2>/dev/null || true
elif [ -n "$RUSTFS_USERNAME" ] && [ -n "$RUSTFS_GROUPNAME" ]; then
chown "$RUSTFS_USERNAME:$RUSTFS_GROUPNAME" "$vol" 2>/dev/null || true
fi
fi
done
}
# 3) Process log directory (separate from data volumes)
process_log_directory() {
# Output logs to stdout
if [ -z "$RUSTFS_OBS_LOG_DIRECTORY" ]; then
echo "OBS log directory not configured and logs outputs to stdout"
return
fi
# Output logs to remote endpoint
if [ "${RUSTFS_OBS_LOG_DIRECTORY}" != "${RUSTFS_OBS_LOG_DIRECTORY#*://}" ]; then
echo "Output logs to remote endpoint"
return
fi
# Outputs logs to local directory
LOG_DIR="${RUSTFS_OBS_LOG_DIRECTORY}"
echo "Initializing log directory: $LOG_DIR"
if [ ! -d "$LOG_DIR" ]; then
echo " mkdir -p $LOG_DIR"
mkdir -p "$LOG_DIR"
# If target user is specified, try to set directory owner to that user (non-recursive to avoid large disk overhead)
if [ -n "$RUSTFS_UID" ] && [ -n "$RUSTFS_GID" ]; then
chown "$RUSTFS_UID:$RUSTFS_GID" "$LOG_DIR" 2>/dev/null || true
elif [ -n "$RUSTFS_USERNAME" ] && [ -n "$RUSTFS_GROUPNAME" ]; then
chown "$RUSTFS_USERNAME:$RUSTFS_GROUPNAME" "$LOG_DIR" 2>/dev/null || true
fi
fi
}
# Execute the separate processes
process_data_volumes
process_log_directory
# 4) Default credentials warning
if [ "${RUSTFS_ACCESS_KEY}" = "rustfsadmin" ] || [ "${RUSTFS_SECRET_KEY}" = "rustfsadmin" ]; then
echo "!!!WARNING: Using default RUSTFS_ACCESS_KEY or RUSTFS_SECRET_KEY. Override them in production!"
fi
# 5) Append DATA_VOLUMES only if no data paths in arguments
# Check if any argument looks like a data path (starts with / and not an option)
HAS_DATA_PATH=false
for arg in "$@"; do
case "$arg" in
/usr/bin/rustfs) continue ;;
-*) continue ;;
/*) HAS_DATA_PATH=true; break ;;
esac
done
if [ "$HAS_DATA_PATH" = "false" ] && [ -n "$DATA_VOLUMES" ]; then
echo "Starting: $* $DATA_VOLUMES"
set -- "$@" $DATA_VOLUMES
else
echo "Starting: $*"
fi
exec "$@"