diff options
author | Marcel Saegebarth <marc@mos6581.de> | 2015-02-23 18:31:39 +0100 |
---|---|---|
committer | Willy Sudiarto Raharjo <willysr@slackbuilds.org> | 2015-02-28 03:01:51 +0700 |
commit | 86fa2f111f4904da8199c9ec812450e9a79d1822 (patch) | |
tree | 16427bac032b2a9d81b8119cde94a345c8bda1d1 /network/seafile-server/seafile | |
parent | 8fdad9c92d349858aa0487025c96d3f7c540a35f (diff) |
network/seafile-server: Added garbage collector and fix long option.
Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
Diffstat (limited to 'network/seafile-server/seafile')
-rw-r--r-- | network/seafile-server/seafile | 75 |
1 files changed, 71 insertions, 4 deletions
diff --git a/network/seafile-server/seafile b/network/seafile-server/seafile index 04545319321d0..fd80c1d68b4bf 100644 --- a/network/seafile-server/seafile +++ b/network/seafile-server/seafile @@ -1,6 +1,6 @@ #!/bin/sh -# Simple `seafile-admin` wrapper script. +# Simple `seafile-admin` & `seafserv-gc` wrapper script. # Copyright 2015 Marcel Saegebarth <marc@mos6581.de> # All rights reserved. @@ -24,18 +24,82 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THIS_NAME=$(basename ${0}) WORKING_DIR=${WORKING_DIR:-/opt/haiwen} PYTHONPATH=$WORKING_DIR/seafile-server/seahub/thirdpart:$PYTHONPATH PATH=$PYTHONPATH:$PATH SEAFILEUSER=seafile +SEAFILEDATA=${SEAFILEDATA:-""} +OPTHELP=${OPTHELP:-no} +ARGUMENTS=${ARGUMENTS:-$1} -set -e +set -o pipefail +set -o nounset + +alias printf=$(command -v printf) + +getopt -T > /dev/null +if [ $? -eq 4 ]; then + ARGS=$(getopt -a -n "$THIS_NAME" -l data-directory:,help -o d:h -- "$@") + if [ $? -ne 0 ]; then + printf '\n' && exit 1 + fi + eval set -- $ARGS +else + printf '%s\n' "Failed: Require GNU enhanced version. Exit." && exit 1 +fi + +while [ $# -gt 0 ]; do + case "$1" in + -d | --data-directory) SEAFILEDATA=$2 ;; + -h | --help) OPTHELP=yes ;; + --) shift; break;; + esac + shift +done + +if [ "$OPTHELP" = "yes" ]; then + cat << EOF +${THIS_NAME} + +Usage: seafile start|stop|restart|setup|create-admin|reset-admin|cleanup [-d <seafile-data-directory>] + +Options + -d, --data-directory Specify seafile data directory for garbage collector or + alternatively set the SEAFILEDATA environment variable. + if not used it will ask for the directory. + -h, --help Displays this help message. +EOF + exit 0 +fi execute () { su -s /bin/sh -l $SEAFILEUSER -c "export PYTHONPATH=$PYTHONPATH PATH=$PATH && cd $WORKING_DIR && seafile-admin $1" } -case "$1" in +garbage_collector () { + if [ -z "$SEAFILEDATA" ]; then + read -p 'Enter seafile data directory: ' SEAFILEDATA + fi + + # check if directory + if [ ! -d "$SEAFILEDATA" ]; then + printf '\n%s\n' "Couldn't find directory '$SEAFILEDATA'" && exit 1 + fi + + # check if correct directory by checking for 'seafile.db' + if [ ! -f "$SEAFILEDATA/seafile.db" ]; then + printf '\n%s\n' "Couldn't find 'seafile.db' in directory '$SEAFILEDATA'" && exit 1 + fi + + # as from the manual, stop seafile first and start again after the garbage + # collection + execute stop && \ + su -s /bin/sh -l $SEAFILEUSER -c "seafserv-gc -c \"$WORKING_DIR/ccnet\" -d \"$SEAFILEDATA\"" && \ + execute start +} + +case "$ARGUMENTS" in start) execute start ;; @@ -54,9 +118,12 @@ case "$1" in create-admin) execute create-admin ;; + cleanup) + garbage_collector + ;; *) cat << EOF -Usage: seafile start|stop|restart|setup|create-admin|reset-admin +Usage: seafile start|stop|restart|setup|create-admin|reset-admin|cleanup [-d <seafile-data-directory>] EOF ;; esac |