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-23 03:43:24 +00:00
|
|
|
if [[ -z "${MARIADB_HOST}" && -z "${POSTGRES_HOST}" ]]; then
|
|
|
|
echo "MARIADB_HOST or POSTGRES_HOST is not set" >&2
|
|
|
|
exit 1
|
2020-02-10 08:00:54 +00:00
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${REDIS_CACHE}" ]]; then
|
2021-06-23 03:43:24 +00:00
|
|
|
echo "REDIS_CACHE is not set" >&2
|
2020-02-10 08:00:54 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${REDIS_QUEUE}" ]]; then
|
2021-06-23 03:43:24 +00:00
|
|
|
echo "REDIS_QUEUE is not set" >&2
|
2020-02-10 08:00:54 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${REDIS_SOCKETIO}" ]]; then
|
2021-06-23 03:43:24 +00:00
|
|
|
echo "REDIS_SOCKETIO is not set" >&2
|
2020-02-10 08:00:54 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${SOCKETIO_PORT}" ]]; then
|
2021-06-23 03:43:24 +00:00
|
|
|
echo "SOCKETIO_PORT is not set" >&2
|
2020-02-10 08:00:54 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-22 10:14:25 +00:00
|
|
|
if [[ -z "${DB_PORT}" ]]; then
|
2021-06-24 12:07:15 +00:00
|
|
|
export DB_PORT=3306
|
2020-06-29 17:58:10 +00:00
|
|
|
fi
|
|
|
|
|
2021-06-23 06:56:11 +00:00
|
|
|
export DB_HOST="${MARIADB_HOST:-$POSTGRES_HOST}"
|
2020-06-29 17:58:10 +00:00
|
|
|
|
2021-11-09 10:05:29 +00:00
|
|
|
# shellcheck disable=SC2016
|
2020-06-29 17:58:10 +00:00
|
|
|
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-24 11:24:17 +00:00
|
|
|
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/check_connection.py
|
2020-02-10 08:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkConfigExists() {
|
|
|
|
COUNTER=0
|
2021-06-23 03:43:24 +00:00
|
|
|
while [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json && ${COUNTER} -le 30 ]]; do
|
2021-06-22 10:14:25 +00:00
|
|
|
sleep 1
|
|
|
|
((COUNTER = COUNTER + 1))
|
2021-06-23 03:43:24 +00:00
|
|
|
echo "config file not created, retry ${COUNTER}" >&2
|
2020-02-10 08:00:54 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
if [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json ]]; then
|
2021-06-23 03:43:24 +00:00
|
|
|
echo "timeout: config file not created" >&2
|
2020-02-10 08:00:54 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ ! -e /home/frappe/frappe-bench/sites/apps.txt ]]; then
|
2021-06-23 03:43:24 +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-23 03:43:24 +00:00
|
|
|
case "$1" in
|
2021-03-20 08:27:53 +00:00
|
|
|
|
2021-11-09 10:05:29 +00:00
|
|
|
start)
|
|
|
|
configureEnv
|
|
|
|
checkConnection
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-11-09 10:05:29 +00:00
|
|
|
[[ -z "${WORKERS}" ]] && WORKERS='2'
|
2021-03-20 08:27:53 +00:00
|
|
|
|
2021-11-09 10:05:29 +00:00
|
|
|
[[ -z "${FRAPPE_PORT}" ]] && FRAPPE_PORT='8000'
|
2020-10-01 08:42:55 +00:00
|
|
|
|
2021-11-09 10:05:29 +00:00
|
|
|
[[ -z "${WORKER_CLASS}" ]] && WORKER_CLASS='gthread'
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-11-09 10:05:29 +00:00
|
|
|
LOAD_CONFIG_FILE=""
|
|
|
|
[[ "${WORKER_CLASS}" == "gevent" ]] &&
|
|
|
|
LOAD_CONFIG_FILE="-c /home/frappe/frappe-bench/commands/gevent_patch.py"
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-11-09 10:05:29 +00:00
|
|
|
if [[ -n "${AUTO_MIGRATE}" ]]; then
|
|
|
|
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/auto_migrate.py
|
|
|
|
fi
|
2020-03-26 18:58:50 +00:00
|
|
|
|
2021-11-09 10:05:29 +00:00
|
|
|
# shellcheck disable=SC2086
|
|
|
|
/home/frappe/frappe-bench/env/bin/gunicorn ${LOAD_CONFIG_FILE} -b 0.0.0.0:${FRAPPE_PORT} \
|
|
|
|
--worker-tmp-dir /dev/shm \
|
|
|
|
--threads=4 \
|
|
|
|
--workers ${WORKERS} \
|
|
|
|
--worker-class=${WORKER_CLASS} \
|
|
|
|
--log-file=- \
|
|
|
|
-t 120 frappe.app:application --preload
|
|
|
|
;;
|
|
|
|
|
|
|
|
worker)
|
|
|
|
checkConfigExists
|
|
|
|
checkConnection
|
|
|
|
|
|
|
|
: "${WORKER_TYPE:=default}"
|
|
|
|
bench worker --queue $WORKER_TYPE
|
|
|
|
;;
|
|
|
|
|
|
|
|
schedule)
|
|
|
|
checkConfigExists
|
|
|
|
checkConnection
|
|
|
|
|
|
|
|
bench schedule
|
|
|
|
;;
|
|
|
|
|
|
|
|
new)
|
|
|
|
checkConfigExists
|
|
|
|
checkConnection
|
|
|
|
|
|
|
|
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/new.py
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
|
|
|
drop)
|
|
|
|
checkConfigExists
|
|
|
|
checkConnection
|
|
|
|
|
|
|
|
: "${SITE_NAME:=site1.localhost}"
|
|
|
|
: "${DB_ROOT_USER:=root}"
|
|
|
|
: "${DB_ROOT_PASSWORD:=$POSTGRES_PASSWORD}"
|
|
|
|
: "${DB_ROOT_PASSWORD:=$MYSQL_ROOT_PASSWORD}"
|
|
|
|
: "${DB_ROOT_PASSWORD:=admin}"
|
2021-11-09 13:49:40 +00:00
|
|
|
|
|
|
|
FLAGS=
|
|
|
|
if [[ ${NO_BACKUP} == 1 ]]; then
|
|
|
|
FLAGS="${FLAGS} --no-backup"
|
2021-11-09 10:05:29 +00:00
|
|
|
fi
|
2021-11-09 13:49:40 +00:00
|
|
|
if [[ ${FORCE} == 1 ]]; then
|
|
|
|
FLAGS="${FLAGS} --force"
|
2021-11-09 10:05:29 +00:00
|
|
|
fi
|
2021-11-08 13:10:26 +00:00
|
|
|
|
2021-11-09 13:54:02 +00:00
|
|
|
# shellcheck disable=SC2086
|
2021-11-09 10:05:29 +00:00
|
|
|
bench drop-site \
|
2021-11-09 13:49:40 +00:00
|
|
|
${SITE_NAME} \
|
|
|
|
--root-login ${DB_ROOT_USER} \
|
|
|
|
--root-password ${DB_ROOT_PASSWORD} \
|
2021-11-09 10:05:29 +00:00
|
|
|
--archived-sites-path /home/frappe/frappe-bench/sites/archive_sites \
|
2021-11-09 13:49:40 +00:00
|
|
|
${FLAGS}
|
2021-11-09 10:05:29 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
migrate)
|
|
|
|
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/migrate.py
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
|
|
|
doctor)
|
|
|
|
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/doctor.py "${@:2}"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
|
|
|
backup)
|
2021-11-09 12:15:33 +00:00
|
|
|
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/backup.py
|
|
|
|
exit
|
2021-11-09 10:05:29 +00:00
|
|
|
;;
|
2021-06-23 03:43:24 +00:00
|
|
|
|
2021-11-09 10:05:29 +00:00
|
|
|
console)
|
|
|
|
if [[ -z "$2" ]]; then
|
|
|
|
echo "Need to specify a sitename with the command:" >&2
|
|
|
|
echo "console <sitename>" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2021-11-09 10:05:29 +00:00
|
|
|
bench --site "$2" console
|
|
|
|
;;
|
|
|
|
|
|
|
|
push-backup)
|
|
|
|
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/push_backup.py
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
|
|
|
restore-backup)
|
|
|
|
/home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/restore_backup.py
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exec "$@"
|
|
|
|
;;
|
2021-06-23 03:43:24 +00:00
|
|
|
esac
|