-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartup.sh
65 lines (51 loc) · 1.59 KB
/
startup.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
#!/usr/bin/env bash
function cleanup {
kill `pidof tail` 2>/dev/null
kill `pidof java` 2>/dev/null
}
trap cleanup EXIT
trap cleanup INT
cleanup
STATE_DIR=/opt/app/state
# Create the subsonic user using provided uid.
SUBSONIC_UID=${SUBSONIC_UID:-${1:-1000}}
SUBSONIC_GID=${SUBSONIC_GID:-${2:-1000}}
UNAME=`id -u -n ${SUBSONIC_UID} 2>/dev/null`
if [[ $? -ne 0 ]]; then
echo "INFO: Creating subsonic user with uid and gid: ${SUBSONIC_UID}:${SUBSONIC_GID}"
groupadd -g $SUBSONIC_GID subsonic
useradd -g $SUBSONIC_GID -u $SUBSONIC_UID subsonic
UNAME=subsonic
fi
chown -R ${UNAME}:${UNAME} /opt/app/state
# Copy the transcode binaries
if [[ ! -d ${STATE_DIR}/transcode ]]; then
sudo -u ${UNAME} mkdir -p ${STATE_DIR}/transcode
fi
echo "INFO: Copying transcode binaries to state dir"
sudo -u ${UNAME} cp -Rf /opt/ffmpeg/* ${STATE_DIR}/transcode/
echo "INFO: Updating /etc/default/subsonic"
cat > /etc/default/subsonic << EOM
SUBSONIC_ARGS="--max-memory=${SUBSONIC_MAX_MEMORY:-512} --home=${STATE_DIR} --port=4040 --default-music-folder=/mnt/music --context-path=${SUBSONIC_CONTEXT_PATH} ${SUBSONIC_ADDITIONAL}"
SUBSONIC_USER=${UNAME}
export LANG=${LANG}
export LANGUAGE=${LANG}
export LC_ALL=${LANG}
EOM
service subsonic start
RES=$?
if [[ ! ${RES} -eq 0 ]]; then
echo "ERROR: Exit code was ${RES}"
exit 1
fi
TAIL_FILES="${STATE_DIR}/subsonic.log ${STATE_DIR}/subsonic_sh.log"
for WATCH_FILE in $TAIL_FILES; do
while ! stat ${WATCH_FILE} >/dev/null 2>&1; do
echo "Waiting for ${WATCH_FILE}"
sleep 1
done
done
tail -f $TAIL_FILES &
while kill -0 `pidof java` 2>/dev/null; do
sleep 0.5
done