2020-02-10 08:00:54 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function configureEnv() {
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ ! -f /home/frappe/frappe-bench/sites/common_site_config.json ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${MARIADB_HOST}" ]]; then
|
|
|
|
if [[ -z "${POSTGRES_HOST}" ]]; then
|
2020-06-29 17:58:10 +00:00
|
|
|
echo "MARIADB_HOST or POSTGRES_HOST is not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-02-10 08:00:54 +00:00
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${REDIS_CACHE}" ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
echo "REDIS_CACHE is not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${REDIS_QUEUE}" ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
echo "REDIS_QUEUE is not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${REDIS_SOCKETIO}" ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
echo "REDIS_SOCKETIO is not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${SOCKETIO_PORT}" ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
echo "SOCKETIO_PORT is not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${DB_PORT}" ]]; then
|
2020-06-29 17:58:10 +00:00
|
|
|
export DB_PORT=3306
|
|
|
|
fi
|
|
|
|
|
|
|
|
export DB_HOST="${MARIADB_HOST:-$POSTGRES_HOST}"
|
|
|
|
|
|
|
|
envsubst '${DB_HOST}
|
|
|
|
${DB_PORT}
|
2020-02-10 08:00:54 +00:00
|
|
|
${REDIS_CACHE}
|
|
|
|
${REDIS_QUEUE}
|
|
|
|
${REDIS_SOCKETIO}
|
2021-06-22 10:14:25 +00:00
|
|
|
${SOCKETIO_PORT}' </opt/frappe/common_site_config.json.template >/home/frappe/frappe-bench/sites/common_site_config.json
|
2020-02-10 08:00:54 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkConnection() {
|
2021-06-22 10:14:25 +00:00
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
|
|
|
python /home/frappe/frappe-bench/commands/check_connection.py
|
2020-02-10 08:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkConfigExists() {
|
|
|
|
COUNTER=0
|
2021-06-22 10:14:25 +00:00
|
|
|
while [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json ]] && [[ ${COUNTER} -le 30 ]]; do
|
|
|
|
sleep 1
|
|
|
|
((COUNTER = COUNTER + 1))
|
|
|
|
echo "config file not created, retry ${COUNTER}"
|
2020-02-10 08:00:54 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
if [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json ]]; then
|
|
|
|
echo "timeout: config file not created"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ ! -e /home/frappe/frappe-bench/sites/apps.txt ]]; then
|
2021-06-22 10:14:25 +00:00
|
|
|
find /home/frappe/frappe-bench/apps -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort -r >/home/frappe/frappe-bench/sites/apps.txt
|
2020-02-10 08:00:54 +00:00
|
|
|
fi
|
|
|
|
|
2020-08-05 16:10:37 +00:00
|
|
|
# symlink node_modules
|
2020-08-06 09:48:32 +00:00
|
|
|
ln -sfn /home/frappe/frappe-bench/sites/assets/frappe/node_modules \
|
2020-08-05 16:10:37 +00:00
|
|
|
/home/frappe/frappe-bench/apps/frappe/node_modules
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ "$1" == 'start' ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
configureEnv
|
|
|
|
checkConnection
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${WORKERS}" ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
export WORKERS=2
|
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${FRAPPE_PORT}" ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
export FRAPPE_PORT=8000
|
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${WORKER_CLASS}" ]]; then
|
2021-03-20 08:27:53 +00:00
|
|
|
export WORKER_CLASS=gthread
|
|
|
|
fi
|
|
|
|
|
|
|
|
export LOAD_CONFIG_FILE=""
|
2021-06-22 10:14:25 +00:00
|
|
|
if [ "${WORKER_CLASS}" = "gevent" ]; then
|
2021-03-20 08:27:53 +00:00
|
|
|
export LOAD_CONFIG_FILE="-c /home/frappe/frappe-bench/commands/gevent_patch.py"
|
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ ! -z "${AUTO_MIGRATE}" ]]; then
|
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
|
|
|
python /home/frappe/frappe-bench/commands/auto_migrate.py
|
2020-03-21 10:17:35 +00:00
|
|
|
fi
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-02-20 10:54:01 +00:00
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
2021-06-22 10:14:25 +00:00
|
|
|
gunicorn ${LOAD_CONFIG_FILE} -b 0.0.0.0:${FRAPPE_PORT} \
|
2021-02-20 10:54:01 +00:00
|
|
|
--worker-tmp-dir /dev/shm \
|
|
|
|
--threads=4 \
|
2021-06-22 10:14:25 +00:00
|
|
|
--workers ${WORKERS} \
|
|
|
|
--worker-class=${WORKER_CLASS} \
|
2021-02-20 10:54:01 +00:00
|
|
|
--log-file=- \
|
|
|
|
-t 120 frappe.app:application --preload
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
elif [[ "$1" == 'worker' ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
checkConfigExists
|
|
|
|
checkConnection
|
|
|
|
# default WORKER_TYPE=default
|
2021-03-20 08:27:53 +00:00
|
|
|
|
2021-02-20 10:54:01 +00:00
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
|
|
|
python /home/frappe/frappe-bench/commands/worker.py
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
elif [[ "$1" == 'schedule' ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
checkConfigExists
|
|
|
|
checkConnection
|
2021-03-20 08:27:53 +00:00
|
|
|
|
2021-02-20 10:54:01 +00:00
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
|
|
|
python /home/frappe/frappe-bench/commands/background.py
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
elif [[ "$1" == 'new' ]]; then
|
2020-06-12 17:42:52 +00:00
|
|
|
checkConfigExists
|
|
|
|
checkConnection
|
2021-03-20 08:27:53 +00:00
|
|
|
|
2021-02-20 10:54:01 +00:00
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
|
|
|
python /home/frappe/frappe-bench/commands/new.py
|
|
|
|
exit
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
elif [[ "$1" == 'drop' ]]; then
|
2020-10-01 08:42:55 +00:00
|
|
|
checkConfigExists
|
|
|
|
checkConnection
|
2021-03-20 08:27:53 +00:00
|
|
|
|
2021-02-20 10:54:01 +00:00
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
|
|
|
python /home/frappe/frappe-bench/commands/drop.py
|
|
|
|
exit
|
2020-10-01 08:42:55 +00:00
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
elif [[ "$1" = 'migrate' ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
|
|
|
python /home/frappe/frappe-bench/commands/migrate.py
|
2020-02-10 08:00:54 +00:00
|
|
|
exit
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
elif [[ "$1" == 'doctor' ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
|
|
|
python /home/frappe/frappe-bench/commands/doctor.py ${@:2}
|
2020-02-10 08:00:54 +00:00
|
|
|
exit
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
elif [[ "$1" == 'backup' ]]; then
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-02-20 10:54:01 +00:00
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
|
|
|
python /home/frappe/frappe-bench/commands/backup.py
|
|
|
|
exit
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
elif [[ "$1" == 'console' ]]; then
|
2020-02-20 06:38:51 +00:00
|
|
|
|
|
|
|
if [[ -z "$2" ]]; then
|
|
|
|
echo "Need to specify a sitename with the command:"
|
|
|
|
echo "console <sitename>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-02-20 10:54:01 +00:00
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
|
|
|
python /home/frappe/frappe-bench/commands/console.py "$2"
|
|
|
|
exit
|
2020-02-20 06:38:51 +00:00
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
elif [[ "$1" = 'push-backup' ]]; then
|
2020-03-25 01:05:49 +00:00
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
|
|
|
python /home/frappe/frappe-bench/commands/push_backup.py
|
2020-03-25 01:05:49 +00:00
|
|
|
exit
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
elif [[ "$1" = 'restore-backup' ]]; then
|
2020-03-26 18:58:50 +00:00
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
. /home/frappe/frappe-bench/env/bin/activate
|
|
|
|
python /home/frappe/frappe-bench/commands/restore_backup.py
|
2020-03-26 18:58:50 +00:00
|
|
|
exit
|
|
|
|
|
2020-02-10 08:00:54 +00:00
|
|
|
else
|
2020-08-29 18:36:56 +00:00
|
|
|
exec $@
|
2020-02-10 08:00:54 +00:00
|
|
|
|
|
|
|
fi
|