Skip to content

Commit

Permalink
entrypoint refactor
Browse files Browse the repository at this point in the history
- use rest noauth target for health check
- remove jq
  • Loading branch information
k0gen committed Apr 15, 2024
1 parent bbbda43 commit e5e1e39
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM syncthing/syncthing:1.27.6 AS build

RUN apk add --no-cache curl jq tini inotify-tools yq && \
RUN apk add --no-cache curl tini inotify-tools yq && \
rm -rf /var/cache/apk/*

RUN adduser --disabled-password syncthing_user
Expand Down
64 changes: 20 additions & 44 deletions docker_files/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,57 +1,30 @@
#!/bin/sh

printf "\n\n [i] Starting Syncthing ...\n\n"

if ! test -d /mnt/filebrowser
then
exit 0
fi

i=0

rm /root/data/health-web
rm /root/data/health-version
mkdir -p /mnt/filebrowser/syncthing
chown -R syncthing_user /mnt/filebrowser/syncthing
rm -f /root/data/health-web
rm -f /root/data/health-version
export HOME="/mnt/filebrowser/syncthing"
export STHOMEDIR="/mnt/filebrowser/syncthing/.config/syncthing"
su -s /bin/sh -c "syncthing serve --no-restart --reset-deltas --no-default-folder" syncthing_user &
syncthing_process=$!
# wait to fix properties race condition
sleep 2

while [[ "$(syncthing cli show system)" =~ 'no such file or directory' ]] || [[ "$(syncthing cli show system)" =~ 'connection refused' ]] || [[ "$(syncthing cli config gui user get)" =~ 'connection refused' ]]; do
sleep .2
echo "I'm sleeping"
echo "COUNT is $i"
i=$(expr $i + 1)
if test $i -gt 200
then
exit 1
fi
done
echo "Syncthing Settings"
sleep .1
syncthing cli config gui raw-address set -- 0.0.0.0:8384
syncthing cli config gui user set -- $(yq e '.username' /root/data/start9/config.yaml)
syncthing cli config gui password set -- $(yq e '.password' /root/data/start9/config.yaml)
syncthing cli config options uraccepted set -- -1
syncthing cli config defaults device auto-accept-folders set true
syncthing cli config defaults device introducer set true
SU=$(yq '.username' /root/data/start9/config.yaml)
SP=$(yq '.password' /root/data/start9/config.yaml)
ln -s $STHOMEDIR /var/syncthing/config
mkdir -p $HOME
chown -R syncthing_user $HOME

while [[ "$(syncthing cli show system)" =~ 'no such file or directory' ]] || [[ "$(syncthing cli show system)" =~ 'connection refused' ]] || [[ "$(syncthing cli config gui user get)" =~ 'connection refused' ]]; do
sleep .2
echo "I'm sleeping"
echo "COUNT is $i"
i=$(expr $i + 1)
if test $i -gt 200
then
exit 1
fi
done
su-exec syncthing_user syncthing generate --no-default-folder --no-default-folder --skip-port-probing --gui-user=$SU --gui-password=$SP

syncthing cli show system > /root/data/syncthing_stats.json
echo "Adjusting Syncthing Default Settings"
yq -i -p xml -o xml '.configuration.options.urAccepted = "-1"' $STHOMEDIR/config.xml
yq -i -p xml -o xml '.configuration.device.autoAcceptFolders = "true"' $STHOMEDIR/config.xml
yq -i -p xml -o xml '.configuration.defaults.device.+@introducer = "true"' $STHOMEDIR/config.xml

SU=$(yq '.username' /root/data/start9/config.yaml)
SP=$(yq '.password' /root/data/start9/config.yaml)
DID=$(yq -oy '.myID' /root/data/syncthing_stats.json)
DID=$(yq -oy '.configuration.device.+@id' $STHOMEDIR/config.xml)

cat << BTC > /root/data/start9/stats.yaml
---
Expand All @@ -62,7 +35,7 @@ data:
value: $DID
description: This is the ID for syncthing to attach others to this device.
copyable: true
qr: false
qr: true
masked: false
Username:
type: string
Expand All @@ -80,6 +53,9 @@ data:
masked: true
BTC

su-exec syncthing_user syncthing serve --no-restart --reset-deltas --no-default-folder &
syncthing_process=$!

watch-and-own.sh &

health-version.sh &
Expand Down
2 changes: 1 addition & 1 deletion docker_files/health-web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

check_web(){
echo 'Checking web'
curl -u $(yq e '.username' /root/data/start9/config.yaml):$(yq e '.password' /root/data/start9/config.yaml) --silent --fail localhost:8384/ &>/dev/null
curl --silent --fail localhost:8384/rest/noauth/health &>/dev/null
RES=$?
echo RES
if test "$RES" != 0; then
Expand Down

0 comments on commit e5e1e39

Please sign in to comment.