forked from scrapinghub/docker-devpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·59 lines (55 loc) · 2.29 KB
/
run.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
#!/bin/bash
set -e
set -x
# NOTE: This is not the root where the device is mounted. The root often
# has a `lost+found` directory, which will break the initialization
# logic in devpi.
export DEVPISERVER_SERVERDIR=/mnt/devpi-server
# And since this is not the root of the volume, we need to make sure the
# subdirectory we're using is actually there. `-p` will make sure it
# exists (it will create any needed parent directories, and not return
# an error code if the full path already exists).
mkdir -p "$DEVPISERVER_SERVERDIR"
export DEVPI_CLIENTDIR=/tmp/devpi-client
# .serverversion should probably be in this directory, but it's actually
# the .nodeinfo file that devpi uses when checking for existing
# devpi-server data.
[[ -f $DEVPISERVER_SERVERDIR/.nodeinfo ]] || initialize="yes"
kill_devpi() {
test -n "$DEVPI_PID" && kill $DEVPI_PID
}
trap kill_devpi EXIT
# For some reason, killing tail during EXIT trap function triggers an
# "uninitialized stack frame" bug in glibc, so kill tail when handling INT or
# TERM signal.
kill_tail() {
test -n "$TAIL_PID" && kill $TAIL_PID
}
trap kill_tail INT
trap kill_tail TERM
# NOTE: The --init flag is required so that the first time the server
# runs with a given serverdir, necessary groundwork can be put in place.
# If you pass it again, however, you get an error, so we only pass it if
# we are running for the very first time.
if [[ "$initialize" == "yes" ]]; then
devpi-server --start --init --host 0.0.0.0 --port 3141 || \
{ [ -f "$LOG_FILE" ] && cat "$LOG_FILE"; exit 1; }
else
devpi-server --start --host 0.0.0.0 --port 3141 || \
{ [ -f "$LOG_FILE" ] && cat "$LOG_FILE"; exit 1; }
fi
DEVPI_PID="$(cat $DEVPISERVER_SERVERDIR/.xproc/devpi-server/xprocess.PID)"
if [[ "$initialize" == "yes" ]]; then
devpi use http://localhost:3141
devpi login root --password=''
devpi user -m root password="${DEVPI_PASSWORD}"
devpi index -y -c public pypi_whitelist='*'
fi
# We cannot simply execute tail, because otherwise bash won't propagate
# incoming TERM signals to tail and will hang indefinitely. Instead, we wait
# on tail PID and then "wait" command will interrupt on TERM (or any other)
# signal and the script will proceed to kill_* functions which will gracefully
# terminate child processes.
tail -f /etc/fstab & #"$LOG_FILE" &
TAIL_PID=$!
wait $TAIL_PID