#!/bin/sh # # PROVIDE: seahub # REQUIRE: LOGIN cleanvar seafile # KEYWORD: shutdown # # # Add the following lines to /etc/rc.conf to enable seahub: # # seahub_enable (bool): Set to "NO" by default. # Set it to "YES" to enable seahub. # seafile_user (str): User to run seafile as # Default to "%%USERS%%" created by the port # seafile_group (str): Group to run seafile as # Default to "%%GROUPS%%" created by the port # seafile_path (str): Set to "" by default will use the path # %%PREFIX%%/%%SEAFILE_SERVER%%. # Set it to a different path. # seafile_ccnet (str): Set to "" by default will use the path # %%PREFIX%%/%%HAIWENDIR%%/ccnet. # Set it to a different path. # seafile_conf (str): Set to "" by default will use the path # %%PREFIX%%/%%HAIWENDIR%%/conf. # Set it to a different path. # seafile_datadir (str): Set to "" by default will use the path # in file %%PREFIX%%/%%HAIWENDIR%%/ccnet/seafile.ini. # Set it to a different path. # seafile_logdir (str): Set to "" by default will use the path # %%PREFIX%%/%%HAIWENDIR%%/logs. # Set it to a different path. # seahub_fastcgi (bool): Set to "NO" by default. # Set to "YES" to start the fastcgi mode. # seahub_host (int): Default is 127.0.0.1. # seahub_port (int): Default is 8000. . /etc/rc.subr name="seahub" rcvar=seahub_enable load_rc_config $name extra_commands="clearsessions" start_cmd="seahub_start" restart_cmd="seahub_restart" stop_cmd="seahub_stop" clearsessions_cmd="seahub_clearsessions" : ${seahub_enable="NO"} : ${seafile_user:="%%USERS%%"} : ${seafile_group:="%%GROUPS%%"} : ${seafile_path:="%%PREFIX%%/%%SEAFILE_SERVER%%"} : ${seafile_ccnet:="%%PREFIX%%/%%HAIWENDIR%%/ccnet"} : ${seafile_conf:="%%PREFIX%%/%%HAIWENDIR%%/conf"} : ${seafile_datadir:="`cat ${seafile_ccnet}/seafile.ini 2>/dev/null`"} : ${seafile_logdir:="%%PREFIX%%/%%HAIWENDIR%%/logs"} : ${seahub_fastcgi="NO"} : ${seahub_host:="127.0.0.1"} : ${seahub_port:="8000"} manage_py=${seafile_path}/seahub/manage.py gunicorn_exe=%%PREFIX%%/bin/gunicorn gunicorn_conf=${seafile_path}/runtime/seahub.conf pidfile=${seafile_path}/runtime/seahub.pid errorlog=${seafile_path}/runtime/error.log accesslog=${seafile_path}/runtime/access.log command="%%PREFIX%%/bin/%%PYTHON%%" required_dirs="${seafile_ccnet} ${seafile_conf} ${seafile_datadir} ${seafile_logdir}" required_files="${seafile_ccnet}/seafile.ini" validate_seahub_running() { if pgrep -f "${manage_py}" 2>/dev/null 1>&2; then echo "Seahub is already running." exit 1; fi } warning_if_seafile_not_running() { if ! pgrep -f "seafile-controller -c ${seafile_ccnet}" 2>/dev/null 1>&2; then echo echo "Warning: seafile not running. Have you run \"service seafile start\" ?" echo exit 1 fi } prepare_env() { if [ -z "$LANG" ]; then echo "LANG is not set in ENV, set to en_US.UTF-8" export LANG='en_US.UTF-8' fi if [ -z "$LC_ALL" ]; then echo "LC_ALL is not set in ENV, set to en_US.UTF-8" export LC_ALL='en_US.UTF-8' fi export CCNET_CONF_DIR=${seafile_ccnet} export SEAFILE_CONF_DIR=${seafile_datadir} export SEAFILE_CENTRAL_CONF_DIR=${seafile_conf} export PYTHONPATH=${seafile_path}/seafile/lib/python2.6/site-packages:${seafile_path}/seafile/lib64/python2.6/site-packages:${seafile_path}/seahub/thirdpart:$PYTHONPATH export PYTHONPATH=${seafile_path}/seafile/lib/python2.7/site-packages:${seafile_path}/seafile/lib64/python2.7/site-packages:$PYTHONPATH export SEAHUB_LOG_DIR=${seafile_logdir} } before_start() { prepare_env; warning_if_seafile_not_running; validate_seahub_running; } seahub_clearsessions() { prepare_env; echo "Start clear expired session records ..." su -m "${seafile_user}" -c "$command \"${manage_py}\" clearsessions" echo echo "Done" echo } seahub_start() { if checkyesno seahub_enable; then if checkyesno seahub_fastcgi; then echo "Starting seahub service fastcgi mode" check_required_before; before_start; # Returns 127.0.0.1 if SEAFILE_FASTCGI_HOST is unset or hasn't got any value, # otherwise returns value of SEAFILE_FASTCGI_HOST environment variable echo "Starting seahub (fastcgi) at ${seahub_host}:${seahub_port} ..." su -m "${seafile_user}" -c "$command \"${manage_py}\" runfcgi host=\"${seahub_host}\" port=\"${seahub_port}\" pidfile=$pidfile \ outlog=${accesslog} errlog=${errorlog}" # Ensure seahub is started successfully sleep 5 if ! pgrep -f "${manage_py}" 1>/dev/null; then printf "\033[33mError:Seahub failed to start.\033[m\n" exit 1; fi echo echo "Seahub is started" echo else check_required_before; before_start; echo "Starting seahub at port ${seahub_port} ..." su -m "${seafile_user}" -c "$command \"${gunicorn_exe}\" seahub.wsgi:application -c \"${gunicorn_conf}\" -b \"0.0.0.0:${seahub_port}\" --preload --chdir \"$seafile_path/seahub\"" # Ensure seahub is started successfully sleep 5 if ! pgrep -f "seahub.wsgi:application" 2>/dev/null 1>&2; then printf "\033[33mError:Seahub failed to start.\033[m\n" echo "Please try to run \"./seahub.sh start\" again" exit 1; fi echo echo "Seahub is started" echo fi else return 0 fi } seahub_stop() { if [ -f ${pidfile} ]; then pid=$(cat "${pidfile}") echo "Stopping ${name}." kill ${pid} rm -f ${pidfile} return 0 else echo "Seahub is not running" fi } seahub_restart() { seahub_stop; sleep 2 seahub_start; } run_rc_command "$1"