Stop seaf-cli After Sync

Jul 25, 2020

The seaf-cli is a console client to access a Seafile server. It works using a daemon that must be started and stopped. Due to the lack of resources I need to stop the daemon after the sync was done.

Unfortunately seaf-cli doesn’t have an option to stop the daemon after sync. To have this resource I write a simple script called stop-seaf-cli-after-sync.sh. So I just run it after a periodic rsync on files to seafile destination.

stop-seaf-cli-after-sync.sh

#!/bin/sh
CHECK_INTERVAL="30" # seconds
# amount of syn messages to stop seaf-cli
SAFE_SYN=10

syn_count=0
while [ 1 ]; do
        status=`seaf-cli status | tail -n 1 | cut -f 2 | sed 's/ //g'`

        if [ "$status" = "synchronized" ]; then
                syn_count=`expr $syn_count + 1`

                if [ $syn_count = $SAFE_SYN ]; then
                        seaf-cli stop
                        break
                fi
        else
                syn_count=0
        fi

        sleep $CHECK_INTERVAL
done
seafilelanguagesshell-script

Back to talau's home