diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
index d14a2b75bba654a5ef618378b5b200e20ed33518..948324ab3e8820cb5028713f59cd5273ebf3959a 100755
--- a/docker-entrypoint.sh
+++ b/docker-entrypoint.sh
@@ -1,8 +1,22 @@
 #!/usr/bin/env bash
 set -Eeo pipefail
 
+seaf-cli init -d /seafile-data
 if [ -z "$OTP_TOKEN" ]; then
   seaf-cli sync -l "$LIBRARY" -s "$SERVER" -d "/sync" -u "$EMAIL" -p "$PASSWORD" --tfa $(oathtool --totp -b "$OTP_TOKEN")
 else
   seaf-cli sync -l "$LIBRARY" -s "$SERVER" -d "/sync" -u "$EMAIL" -p "$PASSWORD"
 fi
+seaf-cli start
+
+maxretry=4
+retry=0
+
+while [ "$retry" -le "$maxretry" ]; do
+    ps aux | grep seafile | grep -v grep > /dev/null 2> /dev/null || {
+        retry=$(expr $retry + 1);
+    }
+    sleep 5
+done
+echo "Seafile not running"
+exit 1