-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtuoso-entrypoint.sh_totallyorig
executable file
·271 lines (233 loc) · 5.17 KB
/
virtuoso-entrypoint.sh_totallyorig
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/bin/bash
#
# virtuoso-entrypoint.sh
#
# Copyright (C) 2018 OpenLink Software
#
# This script initializes the Virtuoso database environment inside a Docker container
#
#set -x
#set -Eeo pipefail
#
# Set mask for file permissions
#
umask 0027
#
# Default programs
#
export VIRTUOSO="$VIRTUOSO_HOME/bin/virtuoso-t"
export INIFILE="$VIRTUOSO_HOME/bin/inifile"
export ISQL="$VIRTUOSO_HOME/bin/isql"
#
# Get information from environment or file
#
# Usage:
# file_env VAR [DEFAULT]
# This checks if there is an environment variable passed when creating the docker instance, or
# or via a file by checking if ${VAR}_FILE environment exists and points to a readable file. If
# neither exists a default value will be assigned
#
# Examples:
# file_env "DBA_PASSWORD" "unset"
#
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
#
# Special environment variables
#
#
# Allow user to set environment variables to overrule values in the default virtuoso.ini
#
# Environment variables should be named like:
#
# VIRT_SECTION_KEY=VALUE
#
# where
#
# VIRT is common prefix to group such variables together
# SECTION is the name of the [section] in virtuoso.ini
# KEY is the name of a key within the section
# VALUE is the text to be written into the key
#
# The variable names can be placed in either uppercase (most commonly used) or mixed case, without having to exactly match the case inside
# the virtuoso.ini file:
#
# VIRT_Parameters_NumberOfBuffers is same as VIRT_PARAMETERS_NUMBEROFBUFFERS
#
# Examples:
# VIRT_PARAMETERS_NUMBEROFBUFFERS=1000000
# VIRT_HTTPSERVER_PORT=80
#
virtuoso_ini_from_env()
{
printenv | grep -i ^VIRT_ | while read a
do
setting=`echo $a | cut -d'=' -f 1`
value=`echo $a | cut -d'=' -f 2`
section=`echo $setting | cut -d'_' -f 2`
key=`echo $setting | cut -d'_' -f 3-`
"$INIFILE" +inifile virtuoso.ini +section "$section" +key "$key" +value "$value"
done
}
#
# Rewrite Plugins section to only load the plugins that are actually installed on the image
#
virtuoso_ini_plugins()
{
$INIFILE -f virtuoso.ini -s Plugins -k - -v -
$INIFILE -f virtuoso.ini -s Plugins -k LoadPath -v ../hosting
i=0
for f in "$VIRTUOSO_HOME"/hosting/*.so
do
bf=`basename $f .so`
i=$((i + 1))
inifile -f virtuoso.ini -s Plugins -k Load$i -v "plain, $bf"
done
}
#
# Generate a random password
#
generate_initial_password() {
#
# Check if operator has provided a password via the environment or file
#
file_env DBA_PASSWORD unset
file_env DAV_PASSWORD unset
#
# Generate initial password
#
if test "$DBA_PASSWORD" = "ami-id"
then
#
# Special case for AMI installations
#
PW=$(/usr/bin/curl --connect-timeout .5 http://169.254.169.254/latest/meta-data/ami-id 2>/dev/null)
DBA_PASSWORD=${PW:-unset}
fi
if test "$DBA_PASSWORD" = "unset"
then
PW=$(/usr/bin/pwgen -v -s 8 1 2>/dev/null)
DBA_PASSWORD=${PW:-unset}
fi
if test "$DBA_PASSWORD" = "unset"
then
PW=$(/usr/bin/openssl rand -base64 6 2>/dev/null)
DBA_PASSWORD=${PW:-unset}
fi
if test "$DBA_PASSWORD" = "unset"
then
val=$(( 0$RANDOM % 1000))
DBA_PASSWORD="docker-$val"
fi
#
# Use same password for DAV unless the user has set it
#
if test "$DAV_PASSWORD" = "unset"
then
echo "not setting pass"
DAV_PASSWORD="$DBA_PASSWORD"
fi
#
# Save password which is only readable by user that starts docker image (normally root)
#
echo "$DBA_PASSWORD" > /settings/dba_password
echo "$DAV_PASSWORD" > /settings/dav_password
}
#
# Check to see if this instance has already been initialized
#
initialize_virtuoso_directory()
{
if [ \! -f virtuoso.ini ]
then
#
# Check for custom virtuoso.ini
#
if [ -f "$VIRTUOSO_INI_FILE" ]
then
echo "not copying"
cp "$VIRTUOSO_INI_FILE" /database/virtuoso.ini
else
echo "not copying"
cp "$VIRTUOSO_HOME"/installer/virtuoso.ini.sample /database/virtuoso.ini
fi
#
# Rewrite Plugins section
#
virtuoso_ini_plugins
#
# Convert environment variables to virtuoso.ini settings
#
virtuoso_ini_from_env
#
# Generate a password
#
generate_initial_password
#
# Create an initial database
#
$VIRTUOSO -f +checkpoint-only +pwdold dba +pwddba "$DBA_PASSWORD" +pwddav "$DAV_PASSWORD"
#
# Process any initdb.d scripts (TODO)
#
fi
}
#
# Argument parsing
#
CMD=${1-"start"}
shift
#
# RUn command
#
case $CMD in
start)
initialize_virtuoso_directory
exec $VIRTUOSO -f
;;
stop)
if [ -f virtuoso.lck ]
then
source virtuoso.lck
kill -INT $VIRT_PID
fi
exit 0
;;
version)
echo ""
echo "This Docker image is using the following version of Virtuoso:"
echo ""
exec $VIRTUOSO -? 2>&1 | head -5
exit 1
;;
isql)
exec $ISQL localhost:1111 dba dba $*
exit 1
;;
bash)
exec /bin/bash
exit 1
;;
esac
#
# Try to execute the given command
#
echo 'EXECUTING' $CMD
exec "$CMD" $*
#exec "/opt/virtuoso-opensource/bin/virtuoso-t " $*
exit 1