1 #!/bin/bash /etc/rc.common
5 EXTRA_HELP=" clearsessions Clears expired sessions from database"
6 EXTRA_COMMANDS="clearsessions"
10 SEAHUB_METHOD=threaded
13 [ -f /etc/config/seafile ] && \
16 INSTALLPATH=/usr/share/seafile/seafile-server
17 TOPDIR=$(dirname "${INSTALLPATH}")
18 default_ccnet_conf_dir=${TOPDIR}/ccnet
19 central_config_dir=${TOPDIR}/conf
21 manage_py=${INSTALLPATH}/seahub/manage.py
22 gunicorn_conf=${INSTALLPATH}/runtime/seahub.conf
23 pidfile=/var/run/seafile/seahub.pid
24 errorlog=${INSTALLPATH}/runtime/error.log
25 accesslog=${INSTALLPATH}/runtime/access.log
26 gunicorn_exe=/usr/bin/gunicorn
28 function check_python_executable() {
29 if [[ "$PYTHON" != "" && -x $PYTHON ]]; then
33 if which python2.7 2>/dev/null 1>&2; then
35 elif which python27 2>/dev/null 1>&2; then
39 echo "Can't find a python executable of version 2.7 or above in PATH"
40 echo "Install python 2.7+ before continue."
41 echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
47 function validate_ccnet_conf_dir() {
48 if [[ ! -d ${default_ccnet_conf_dir} ]]; then
49 echo "Error: there is no ccnet config directory."
50 echo "Have you run '/etc/init.d/seafile setup'?"
56 function read_seafile_data_dir() {
57 seafile_ini=${default_ccnet_conf_dir}/seafile.ini
58 if [[ ! -f ${seafile_ini} ]]; then
59 echo "Error: ${seafile_ini} not found."
62 seafile_data_dir=$(cat "${seafile_ini}")
63 if [[ ! -d ${seafile_data_dir} ]]; then
64 echo "Your seafile server data directory \"${seafile_data_dir}\" is invalid or doesn't exits."
65 echo "Please check it first, or create this directory yourself."
71 function validate_seahub_running() {
72 if pid=$(pgrep -f "${manage_py}" 2>/dev/null); then
74 elif pid=$(pgrep -f "seahub.wsgi:application" 2>/dev/null); then
79 function validate_port() {
80 if ! [[ ${SEAHUB_PORT} =~ ^[1-9][0-9]{1,4}$ ]] ; then
81 printf "\033[033m${SEAHUB_PORT}\033[m is not a valid port number\n"
86 function warning_if_seafile_not_running() {
87 if ! pgrep -f "seafile-controller -F ${central_config_dir}" 2>/dev/null 1>&2; then
89 echo "Error: seafile-controller not running. Have you run \"/etc/init.d/seafile start\"?"
95 function prepare_seahub_log_dir() {
96 logdir="${TOPDIR}/logs"
97 if ! [[ -d "${logsdir}" ]]; then
98 if ! mkdir -p "${logdir}"; then
99 echo "Error: failed to create log dir \"${logdir}\""
103 export SEAHUB_LOG_DIR="${logdir}"
106 function before_start() {
108 warning_if_seafile_not_running
109 if ! validate_seahub_running; then
110 echo "Seahub is already running."
113 prepare_seahub_log_dir
117 function start_seahub() {
119 echo "Starting seahub at port ${SEAHUB_PORT} ..."
121 $PYTHON $gunicorn_exe seahub.wsgi:application -c "${gunicorn_conf}" -b "0.0.0.0:${SEAHUB_PORT}" --preload
123 # Ensure seahub is started successfully
125 while ! validate_seahub_running && [[ ! -f "${pidfile}" ]] && [[ $retry -lt 120 ]]; do sleep 1; ((retry++)); done
126 if ! validate_seahub_running && [[ -f "${pidfile}" ]]; then
128 echo "Seahub is started"
131 printf "\033[33mError: Seahub failed to start.\033[m\n"
136 function start_seahub_fastcgi() {
139 # Returns 127.0.0.1 if SEAFILE_FASTCGI_HOST is unset or hasn't got any value,
140 # otherwise returns value of SEAFILE_FASTCGI_HOST environment variable
141 address=`(test -z "$SEAFILE_FASTCGI_HOST" && echo "127.0.0.1") || echo $SEAFILE_FASTCGI_HOST`
143 echo "Starting seahub (fastcgi) at ${address}:${SEAHUB_PORT} ..."
145 $PYTHON "${manage_py}" runfcgi host=${address} port=${SEAHUB_PORT} pidfile=${pidfile} \
146 outlog=${accesslog} errlog=${errorlog} maxchildren=${SEAHUB_WORKERS} method=${SEAHUB_METHOD}
148 # Ensure seahub is started successfully
150 while ! validate_seahub_running && [[ ! -f "${pidfile}" ]] && [[ $retry -lt 120 ]]; do sleep 1; ((retry++)); done
151 if ! validate_seahub_running && [[ -f "${pidfile}" ]]; then
153 echo "Seahub is started"
156 printf "\033[33mError: Seahub failed to start.\033[m\n"
161 function prepare_env() {
162 check_python_executable
163 validate_ccnet_conf_dir
164 read_seafile_data_dir
166 export CCNET_CONF_DIR=${default_ccnet_conf_dir}
167 export SEAFILE_CONF_DIR=${seafile_data_dir}
168 export SEAFILE_CENTRAL_CONF_DIR=${central_config_dir}
169 export PYTHONPATH="${INSTALLPATH}/seahub:${INSTALLPATH}/seahub/thirdpart:${PYTHONPATH}"
172 function clear_sessions() {
175 echo "Start clear expired session records ..."
176 $PYTHON "${manage_py}" clearsessions
183 function stop_seahub() {
184 if [[ -f ${pidfile} ]]; then
185 pid=$(cat "${pidfile}")
186 echo "Stopping seahub ..."
190 while ! validate_seahub_running && [ $retry -lt 60 ]; do sleep 1; ((retry++)); done
191 if ! validate_seahub_running; then
192 echo "Error: seahub cannot be stopped. Please try stopping it manually by running \"kill $(echo "$pid" | tr '\n' ' ')\"."
193 echo "To force killing the processes, use \"kill -9 $(echo "$pid" | tr '\n' ' ')\"."
196 echo "Seahub is not running"
200 function check_init_admin() {
201 check_init_admin_script=${INSTALLPATH}/check_init_admin.py
202 if ! $PYTHON $check_init_admin_script; then
208 if [ "$SEAHUB_FASTCGI" == "1" ]; then
224 function clearsessions() {