diff --git a/Dockerfile b/Dockerfile
index ce8bb0fe70f2812b96523f025d550283c3c616de..a0dec3d252a18a9d66537a2d689e7fa383910e91 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -11,7 +11,13 @@ RUN apt-get update && \
     rm -rf /var/lib/apt/lists/*
 
 ADD docker-entrypoint.sh /docker-entrypoint.sh
-    
+
+RUN addgroup --system --gid 1000 seafile-sync && \
+    adduser --system --ingroup seafile-sync --uid 1000 --shell /bin/sh --home /config seafile-sync
+
+USER seafile-sync
+
+ENV TASK="sync"    
 ENV LIBRARY=""
 ENV SERVER=""
 ENV EMAIL=""
diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
index cd7f82d16593e477102a6d0000194ca945d9c002..daaf7550ca233f18c146ebf8029b8ea44dc54b06 100755
--- a/docker-entrypoint.sh
+++ b/docker-entrypoint.sh
@@ -3,41 +3,21 @@ set -Eeo pipefail
 
 trap "exit" INT
 
-seaf-cli init -d /seafile-data
+mkdir -p ~/seafile
+seaf-cli init -d ~/seafile
 seaf-cli start
-tail -f ~/.ccnet/logs/seafile.log &
-
-until [ -S /seafile-data/seafile-data/seafile.sock ]; do
-  sleep 1;
-done
 
 if [ -z "$OTP_TOKEN" ]; then
   echo "syncing library"
-  date
-  seaf-cli sync -l "$LIBRARY" -s "$SERVER" -d "/sync" -u "$EMAIL" -p "$PASSWORD"
+  seaf-cli "$TASK" -l "$LIBRARY" -s "$SERVER" -d "/sync" -u "$EMAIL" -p "$PASSWORD"
 else
   echo "syncing library with OTP"
-  date
-  seaf-cli sync -l "$LIBRARY" -s "$SERVER" -d "/sync" -u "$EMAIL" -p "$PASSWORD" --tfa $(oathtool --totp -b "$OTP_TOKEN")
+  seaf-cli "$TASK" -l "$LIBRARY" -s "$SERVER" -d "/sync" -u "$EMAIL" -p "$PASSWORD" --tfa $(oathtool --totp -b "$OTP_TOKEN")
 fi
 
-maxretry=4
-retry=0
-
-lastoutput=""
-output=""
-
-while [ "$retry" -le "$maxretry" ]; do
-    ps aux | grep seafile | grep -v grep > /dev/null 2> /dev/null || {
-        retry=$(expr $retry + 1);
-    }
-    output=$(seaf-cli status)
-    if [[ "$output" != "$lastoutput" ]]; then
-      date
-      echo "$output"
-      lastoutput="$output"
-    fi
-    sleep 5
+until seaf-cli status | grep synchronized; do
+  seaf-cli status
+  sleep 5
 done
-echo "Seafile not running"
-exit 1
+
+seaf-cli stop