diff --git a/scripts/seaf-encrypt.sh b/scripts/seaf-encrypt.sh index 0c97c1fe77..e0f72513e1 100755 --- a/scripts/seaf-encrypt.sh +++ b/scripts/seaf-encrypt.sh @@ -47,13 +47,13 @@ function check_component_running() { } function validate_already_running () { - if pid=$(pgrep -f "seafile-controller -c ${default_ccnet_conf_dir}" 2>/dev/null); then + if pid=$(pgrep -f "seafile-monitor.sh" 2>/dev/null); then echo "seafile server is still running, stop it by \"seafile.sh stop\"" echo exit 1; fi - check_component_running "seaf-server" "seaf-server -c ${default_ccnet_conf_dir}" + check_component_running "seaf-server" "seaf-server" check_component_running "seafdav" "wsgidav.server.server_cli" } diff --git a/scripts/seaf-fuse.sh b/scripts/seaf-fuse.sh index aad6c5d699..407207559d 100755 --- a/scripts/seaf-fuse.sh +++ b/scripts/seaf-fuse.sh @@ -46,7 +46,7 @@ function validate_seafile_data_dir () { } function validate_already_running () { - if pid=$(pgrep -f "seaf-fuse -c ${default_ccnet_conf_dir}" 2>/dev/null); then + if pid=$(pgrep -f "seaf-fuse" 2>/dev/null); then echo "seaf-fuse is already running, pid $pid" echo exit 1; @@ -54,9 +54,9 @@ function validate_already_running () { } function warning_if_seafile_not_running () { - if ! pgrep -f "seafile-controller -c ${default_ccnet_conf_dir}" 2>/dev/null 1>&2; then + if ! pgrep -f "seafile-monitor.sh" 2>/dev/null 1>&2; then echo - echo "Warning: seafile-controller not running. Have you run \"./seafile.sh start\" ?" + echo "Warning: seafile server not running. Have you run \"./seafile.sh start\" ?" echo fi } @@ -80,7 +80,7 @@ function start_seaf_fuse () { sleep 2 # check if seaf-fuse started successfully - if ! pgrep -f "seaf-fuse -c ${default_ccnet_conf_dir}" 2>/dev/null 1>&2; then + if ! pgrep -f "seaf-fuse" 2>/dev/null 1>&2; then echo "Failed to start seaf-fuse" exit 1; fi @@ -90,13 +90,13 @@ function start_seaf_fuse () { } function stop_seaf_fuse() { - if ! pgrep -f "seaf-fuse -c ${default_ccnet_conf_dir}" 2>/dev/null 1>&2; then + if ! pgrep -f "seaf-fuse" 2>/dev/null 1>&2; then echo "seaf-fuse not running yet" return 1; fi echo "Stopping seaf-fuse ..." - pkill -SIGTERM -f "seaf-fuse -c ${default_ccnet_conf_dir}" + pkill -SIGTERM -f "seaf-fuse" return 0 } diff --git a/scripts/seaf-gc.sh b/scripts/seaf-gc.sh index 46540fecac..9451a80d97 100755 --- a/scripts/seaf-gc.sh +++ b/scripts/seaf-gc.sh @@ -77,14 +77,14 @@ function check_component_running() { } function validate_already_running () { - if pid=$(pgrep -f "seafile-controller -c ${default_ccnet_conf_dir}" 2>/dev/null); then + if pid=$(pgrep -f "seafile-monitor.sh" 2>/dev/null); then echo "seafile server is still running, stop it by \"seafile.sh stop\"" echo exit 1; fi - check_component_running "seaf-server" "seaf-server -c ${default_ccnet_conf_dir}" - check_component_running "fileserver" "fileserver -c ${default_ccnet_conf_dir}" + check_component_running "seaf-server" "seaf-server" + check_component_running "fileserver" "fileserver" check_component_running "seafdav" "wsgidav.server.server_cli" } diff --git a/scripts/seaf-import.sh b/scripts/seaf-import.sh index 4610937ca1..397fb92d42 100755 --- a/scripts/seaf-import.sh +++ b/scripts/seaf-import.sh @@ -50,13 +50,13 @@ function check_component_running() { <<'COMMENT' function validate_already_running () { - if pid=$(pgrep -f "seafile-controller -c ${default_ccnet_conf_dir}" 2>/dev/null); then + if pid=$(pgrep -f "seafile-monitor.sh" 2>/dev/null); then echo "seafile server is still running, stop it by \"seafile.sh stop\"" echo exit 1; fi - check_component_running "seaf-server" "seaf-server -c ${default_ccnet_conf_dir}" + check_component_running "seaf-server" "seaf-server" check_component_running "seafdav" "wsgidav.server.server_cli" } COMMENT diff --git a/scripts/seafile-background-tasks.sh b/scripts/seafile-background-tasks.sh index 82091e2be0..fc1dc7ac4c 100755 --- a/scripts/seafile-background-tasks.sh +++ b/scripts/seafile-background-tasks.sh @@ -80,9 +80,9 @@ function ensure_single_instance () { } function warning_if_seafile_not_running () { - if ! pgrep -f "seafile-controller -c ${default_ccnet_conf_dir}" 2>/dev/null 1>&2; then + if ! pgrep -f "seafile-monitor.sh" 2>/dev/null 1>&2; then echo - echo "Warning: seafile-controller not running. Have you run \"./seafile.sh start\" ?" + echo "Warning: seafile server not running. Have you run \"./seafile.sh start\" ?" echo fi } diff --git a/scripts/seafile-monitor.sh b/scripts/seafile-monitor.sh index 6d8cfd013f..5ec357c5ad 100755 --- a/scripts/seafile-monitor.sh +++ b/scripts/seafile-monitor.sh @@ -6,7 +6,6 @@ TOPDIR=$(dirname "${INSTALLPATH}") default_ccnet_conf_dir=${TOPDIR}/ccnet default_seafile_data_dir=${TOPDIR}/seafile-data central_config_dir=${TOPDIR}/conf -seaf_controller="${INSTALLPATH}/seafile/bin/seafile-controller" pro_pylibs_dir=${INSTALLPATH}/pro/python seafesdir=$pro_pylibs_dir/seafes seahubdir=${INSTALLPATH}/seahub @@ -55,9 +54,18 @@ function check_python_executable() { fi } -function set_jwt_private_key () { +function set_file_config () { + if [ -z "${ENABLE_FILESERVER}" ]; then + export ENABLE_FILESERVER=`awk -F '=' '/\[fileserver\]/{a=1}a==1&&$1~/^use_go_fileserver/{print $2;exit}' ${SEAFILE_CENTRAL_CONF_DIR}/seafile.conf` + fi + if [ -z "${ENABLE_SEAFDAV}" ]; then + export ENABLE_SEAFDAV=`awk -F '=' '/\[WEBDAV\]/{a=1}a==1&&$1~/^enabled/{print $2;exit}' ${SEAFILE_CENTRAL_CONF_DIR}/seafdav.conf` + fi +} + +function set_env_config () { if [ -z "${JWT_PRIVATE_KEY}" ]; then - if [ ! -e "${central_config_dir}/.env" ]; then + if [ ! -e "${SEAFILE_CENTRAL_CONF_DIR}/.env" ]; then echo "Error: .env file not found." echo "Please follow the upgrade manual to set the .env file." echo "" @@ -65,7 +73,7 @@ function set_jwt_private_key () { fi # load the .env file - source "${central_config_dir}/.env" + source "${SEAFILE_CENTRAL_CONF_DIR}/.env" if [ -z "${JWT_PRIVATE_KEY}" ]; then echo "Error: JWT_PRIVATE_KEY not found in .env file." @@ -74,6 +82,11 @@ function set_jwt_private_key () { exit -1; fi export JWT_PRIVATE_KEY=${JWT_PRIVATE_KEY} + export SEAFILE_SERVER_PROTOCOL=${SEAFILE_SERVER_PROTOCOL} + export SEAFILE_SERVER_HOSTNAME=${SEAFILE_SERVER_HOSTNAME} + export SITE_ROOT=${SITE_ROOT} + export ENABLE_FILESERVER=${ENABLE_FILESERVER} + export ENABLE_SEAFDAV=${ENABLE_SEAFDAV} fi } @@ -96,13 +109,78 @@ function check_process() { } # start +function start_seaf_server() { + LD_LIBRARY_PATH=${SEAFILE_LD_LIBRARY_PATH} ${INSTALLPATH}/seafile/bin/seaf-server \ + -F ${SEAFILE_CENTRAL_CONF_DIR} \ + -c ${CCNET_CONF_DIR} \ + -d ${SEAFILE_CONF_DIR} \ + -l ${TOPDIR}/logs/seafile.log \ + -P ${TOPDIR}/pids/seaf-server.pid \ + -p ${SEAFILE_RPC_PIPE_PATH} \ + -f -L ${TOPDIR} & + sleep 1 +} + +function start_fileserver() { + ${INSTALLPATH}/seafile/bin/fileserver \ + -F ${SEAFILE_CENTRAL_CONF_DIR} \ + -d ${SEAFILE_CONF_DIR} \ + -l ${TOPDIR}/logs/fileserver.log \ + -p ${SEAFILE_RPC_PIPE_PATH} \ + -P ${TOPDIR}/pids/fileserver.pid & + sleep 1 +} + function start_seafevents() { check_python_executable; - $PYTHON -m seafevents.main --config-file ${central_config_dir}/seafevents.conf --logfile ${TOPDIR}/logs/seafevents.log -P ${TOPDIR}/pids/seafevents.pid & + $PYTHON -m seafevents.main \ + --config-file ${SEAFILE_CENTRAL_CONF_DIR}/seafevents.conf \ + --logfile ${TOPDIR}/logs/seafevents.log \ + -P ${TOPDIR}/pids/seafevents.pid & + sleep 1 +} + +function start_seafdav() { + check_python_executable; + SEAFDAV_HOST="0.0.0.0" + SEAFDAV_PORT=8080 + seafdav_host=`awk -F '=' '/\[WEBDAV\]/{a=1}a==1&&$1~/^host/{print $2;exit}' ${SEAFILE_CENTRAL_CONF_DIR}/seafdav.conf` + seafdav_port=`awk -F '=' '/\[WEBDAV\]/{a=1}a==1&&$1~/^port/{print $2;exit}' ${SEAFILE_CENTRAL_CONF_DIR}/seafdav.conf` + if [ $seafdav_host ]; then + SEAFDAV_HOST=$seafdav_host + fi + if [ $seafdav_port ]; then + SEAFDAV_PORT=$((seafdav_port)) + fi + $PYTHON -m wsgidav.server.server_cli \ + --server gunicorn \ + --root / \ + --log-file ${TOPDIR}/logs/seafdav.log \ + --pid ${TOPDIR}/pids/seafdav.pid \ + --port ${SEAFDAV_PORT} \ + --host ${SEAFDAV_HOST} & sleep 1 } # monitor +function monitor_seaf_server() { + process_name="seaf-server" + check_num=$(check_process $process_name) + if [ $check_num -eq 0 ]; then + log "Start $process_name" + start_seaf_server + fi +} + +function monitor_fileserver() { + process_name="fileserver" + check_num=$(check_process $process_name) + if [ $check_num -eq 0 ]; then + log "Start $process_name" + start_fileserver + fi +} + function monitor_seafevents() { process_name="seafevents.main" check_num=$(check_process $process_name) @@ -112,21 +190,40 @@ function monitor_seafevents() { fi } -# check enabled -ENABLE_NOTIFICATION_SERVER=`awk -F '=' '/\[notification\]/{a=1}a==1&&$1~/^enabled/{print $2;exit}' ${central_config_dir}/seafile.conf` -IS_PRO_SEAFEVENTS=`awk '/is_pro/{getline;print $2;exit}' ${pro_pylibs_dir}/seafevents/seafevents_api.py` +function monitor_seafdav() { + process_name="wsgidav.server.server_cli" + check_num=$(check_process $process_name) + if [ $check_num -eq 0 ]; then + log "Start $process_name" + start_seafdav + fi +} -set_jwt_private_key; + +# check enabled +set_file_config + +set_env_config; log "Start Monitor" while [ 1 ]; do + monitor_seaf_server + + if [ $ENABLE_FILESERVER ]; then + monitor_fileserver + fi + if [ $CLUSTER_MODE ] && [ $CLUSTER_MODE = "backend" ]; then : else monitor_seafevents fi + if [ $ENABLE_SEAFDAV ]; then + monitor_seafdav + fi + sleep 30 done diff --git a/scripts/seafile.sh b/scripts/seafile.sh index 3000bfe4b2..d2ee512ab9 100755 --- a/scripts/seafile.sh +++ b/scripts/seafile.sh @@ -18,14 +18,17 @@ TOPDIR=$(dirname "${INSTALLPATH}") default_ccnet_conf_dir=${TOPDIR}/ccnet default_seafile_data_dir=${TOPDIR}/seafile-data central_config_dir=${TOPDIR}/conf -seaf_controller="${INSTALLPATH}/seafile/bin/seafile-controller" pro_pylibs_dir=${INSTALLPATH}/pro/python seafesdir=$pro_pylibs_dir/seafes -IS_PRO_SEAFEVENTS=`awk '/is_pro/{getline;print $2;exit}' ${pro_pylibs_dir}/seafevents/seafevents_api.py` +seafile_rpc_pipe_path=${INSTALLPATH}/runtime export PATH=${INSTALLPATH}/seafile/bin:$PATH export ORIG_LD_LIBRARY_PATH=${LD_LIBRARY_PATH} export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH} +export SEAFILE_CENTRAL_CONF_DIR=${central_config_dir} +export CCNET_CONF_DIR=${default_ccnet_conf_dir} +export SEAFILE_CONF_DIR=${default_seafile_data_dir} +export SEAFILE_RPC_PIPE_PATH=${seafile_rpc_pipe_path} script_name=$0 function usage () { @@ -57,7 +60,7 @@ if [[ -d ${INSTALLPATH}/pro ]]; then export SEAFES_DIR=$seafesdir fi -function set_jwt_private_key () { +function set_env_config () { if [ -z "${JWT_PRIVATE_KEY}" ]; then if [ ! -e "${central_config_dir}/.env" ]; then echo "Error: .env file not found." @@ -76,6 +79,11 @@ function set_jwt_private_key () { exit -1; fi export JWT_PRIVATE_KEY=${JWT_PRIVATE_KEY} + export SEAFILE_SERVER_PROTOCOL=${SEAFILE_SERVER_PROTOCOL} + export SEAFILE_SERVER_HOSTNAME=${SEAFILE_SERVER_HOSTNAME} + export SITE_ROOT=${SITE_ROOT} + export ENABLE_FILESERVER=${ENABLE_FILESERVER} + export ENABLE_SEAFDAV=${ENABLE_SEAFDAV} fi } @@ -97,12 +105,6 @@ function validate_seafile_data_dir () { fi } -function test_config() { - if ! LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_controller} -t -c "${default_ccnet_conf_dir}" -d "${default_seafile_data_dir}" -F "${central_config_dir}" ; then - exit 1; - fi -} - function check_component_running() { name=$1 cmd=$2 @@ -118,81 +120,73 @@ function check_component_running() { } function validate_already_running () { - if pid=$(pgrep -f "seafile-controller -c ${default_ccnet_conf_dir}" 2>/dev/null); then - echo "Seafile controller is already running, pid $pid" + if pid=$(pgrep -f "seafile-monitor.sh" 2>/dev/null); then + echo "Seafile monitor is already running, pid $pid" echo exit 1; fi - check_component_running "seaf-server" "seaf-server -c ${default_ccnet_conf_dir}" - check_component_running "fileserver" "fileserver -c ${default_ccnet_conf_dir}" + check_component_running "seaf-server" "seaf-server" + check_component_running "fileserver" "fileserver" check_component_running "seafdav" "wsgidav.server.server_cli" check_component_running "seafevents" "seafevents.main --config-file ${central_config_dir}" } function start_seafile_server () { - set_jwt_private_key; + set_env_config; validate_already_running; validate_central_conf_dir; validate_seafile_data_dir; validate_running_user; - if [[ $IS_PRO_SEAFEVENTS = "True" ]]; then - test_config; - fi - echo "Starting seafile server, please wait ..." mkdir -p $TOPDIR/logs - if [[ $IS_PRO_SEAFEVENTS = "True" ]]; then - if ! LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_controller} -c "${default_ccnet_conf_dir}" -d "${default_seafile_data_dir}" -F "${central_config_dir}"; then - controller_log="$default_seafile_data_dir/controller.log" - echo - echo "Failed to start seafile server. See $controller_log for more details." - echo - exit 1 - fi - else - LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_controller} \ - -c "${default_ccnet_conf_dir}" \ - -d "${default_seafile_data_dir}" \ - -F "${central_config_dir}" - fi + # seaf-server + LD_LIBRARY_PATH=${SEAFILE_LD_LIBRARY_PATH} ${INSTALLPATH}/seafile/bin/seaf-server \ + -F ${SEAFILE_CENTRAL_CONF_DIR} \ + -c ${CCNET_CONF_DIR} \ + -d ${SEAFILE_CONF_DIR} \ + -l ${TOPDIR}/logs/seafile.log \ + -P ${TOPDIR}/pids/seaf-server.pid \ + -p ${SEAFILE_RPC_PIPE_PATH} \ + -f -L ${TOPDIR} & - sleep 3 + sleep 2 + + # seafile-monitor + ${INSTALLPATH}/seafile-monitor.sh &>> ${TOPDIR}/logs/seafile-monitor.log & + + sleep 1 # check if seafile server started successfully - if ! pgrep -f "seafile-controller -c ${default_ccnet_conf_dir}" 2>/dev/null 1>&2; then + if ! pgrep -f "seaf-server" 2>/dev/null 1>&2; then echo "Failed to start seafile server" + kill_all exit 1; fi - # seafevents, notification-sever - ${INSTALLPATH}/seafile-monitor.sh &>> ${TOPDIR}/logs/seafile-monitor.log & - echo "Seafile server started" echo } function kill_all () { - pkill -f "seaf-server -c ${default_ccnet_conf_dir}" - pkill -f "fileserver -c ${default_ccnet_conf_dir}" + pkill -f "seaf-server" + pkill -f "fileserver" pkill -f "seafevents.main" - pkill -f "wsgidav.server.server_cli" - pkill -f "notification-server -c ${central_config_dir}" - pkill -f "seafile-monitor.sh" + pkill -f "wsgidav.server.server_cli" + pkill -f "seafile-monitor.sh" } function stop_seafile_server () { - if ! pgrep -f "seafile-controller -c ${default_ccnet_conf_dir}" 2>/dev/null 1>&2; then + if ! pgrep -f "seafile-monitor.sh" 2>/dev/null 1>&2; then echo "seafile server not running yet" kill_all return 1 fi echo "Stopping seafile server ..." - pkill -SIGTERM -f "seafile-controller -c ${default_ccnet_conf_dir}" kill_all return 0 diff --git a/scripts/seahub.sh b/scripts/seahub.sh index cddd5a84e0..88843ca688 100755 --- a/scripts/seahub.sh +++ b/scripts/seahub.sh @@ -126,9 +126,9 @@ else fi function warning_if_seafile_not_running () { - if ! pgrep -f "seafile-controller -c ${default_ccnet_conf_dir}" 2>/dev/null 1>&2; then + if ! pgrep -f "seafile-monitor.sh" 2>/dev/null 1>&2; then echo - echo "Warning: seafile-controller not running. Have you run \"./seafile.sh start\" ?" + echo "Warning: seafile server not running. Have you run \"./seafile.sh start\" ?" echo exit 1 fi @@ -186,7 +186,7 @@ function start_seahub () { echo } -function set_jwt_private_key () { +function set_env_config () { if [ -z "${JWT_PRIVATE_KEY}" ]; then if [ ! -e "${central_config_dir}/.env" ]; then echo "Error: .env file not found." @@ -205,11 +205,16 @@ function set_jwt_private_key () { exit -1; fi export JWT_PRIVATE_KEY=${JWT_PRIVATE_KEY} + export SEAFILE_SERVER_PROTOCOL=${SEAFILE_SERVER_PROTOCOL} + export SEAFILE_SERVER_HOSTNAME=${SEAFILE_SERVER_HOSTNAME} + export SITE_ROOT=${SITE_ROOT} + export ENABLE_SEADOC=${ENABLE_SEADOC} + export SEADOC_SERVER_URL=${SEADOC_SERVER_URL} fi } function prepare_env() { - set_jwt_private_key; + set_env_config; check_python_executable; validate_seafile_data_dir;