mirror of
https://github.com/frappe/frappe_docker.git
synced 2026-06-22 07:45:09 +00:00
Merge pull request #295 from revant/feat-doctor-ping-services
feat: ping additional services using doctor
This commit is contained in:
commit
1867a541c6
4 changed files with 75 additions and 10 deletions
|
|
@ -53,18 +53,32 @@ def get_config():
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
# Check mariadb
|
# Check service
|
||||||
def check_mariadb(retry=10, delay=3, print_attempt=True):
|
def check_service(
|
||||||
|
retry=10,
|
||||||
|
delay=3,
|
||||||
|
print_attempt=True,
|
||||||
|
service_name=None,
|
||||||
|
service_port=None):
|
||||||
|
|
||||||
config = get_config()
|
config = get_config()
|
||||||
|
if not service_name:
|
||||||
|
service_name = config.get(DB_HOST_KEY, 'mariadb')
|
||||||
|
if not service_port:
|
||||||
|
service_port = config.get(DB_PORT_KEY, DB_PORT)
|
||||||
|
|
||||||
is_db_connected = False
|
is_db_connected = False
|
||||||
is_db_connected = check_host(
|
is_db_connected = check_host(
|
||||||
config.get(DB_HOST_KEY, 'mariadb'),
|
service_name,
|
||||||
config.get(DB_PORT_KEY, DB_PORT),
|
service_port,
|
||||||
retry,
|
retry,
|
||||||
delay,
|
delay,
|
||||||
print_attempt)
|
print_attempt)
|
||||||
if not is_db_connected:
|
if not is_db_connected:
|
||||||
print("Connection to MariaDB timed out")
|
print("Connection to {service_name}:{service_port} timed out".format(
|
||||||
|
service_name=service_name,
|
||||||
|
service_port=service_port,
|
||||||
|
))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -128,7 +142,7 @@ def get_site_config(site_name):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
check_mariadb()
|
check_service()
|
||||||
check_redis_queue()
|
check_redis_queue()
|
||||||
check_redis_cache()
|
check_redis_cache()
|
||||||
check_redis_socketio()
|
check_redis_socketio()
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,31 @@
|
||||||
|
import argparse
|
||||||
|
|
||||||
from check_connection import (
|
from check_connection import (
|
||||||
check_mariadb,
|
check_service,
|
||||||
check_redis_cache,
|
check_redis_cache,
|
||||||
check_redis_queue,
|
check_redis_queue,
|
||||||
check_redis_socketio,
|
check_redis_socketio,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
'-p',
|
||||||
|
'--ping-service',
|
||||||
|
dest='ping_services',
|
||||||
|
action='append',
|
||||||
|
type=str,
|
||||||
|
help='list of services to ping, e.g. doctor -p "postgres:5432" --ping-service "mariadb:3306"',
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
check_mariadb(retry=1, delay=0, print_attempt=False)
|
args = parse_args()
|
||||||
print("MariaDB Connected")
|
check_service(retry=1, delay=0, print_attempt=False)
|
||||||
|
print("Bench database Connected")
|
||||||
check_redis_cache(retry=1, delay=0, print_attempt=False)
|
check_redis_cache(retry=1, delay=0, print_attempt=False)
|
||||||
print("Redis Cache Connected")
|
print("Redis Cache Connected")
|
||||||
check_redis_queue(retry=1, delay=0, print_attempt=False)
|
check_redis_queue(retry=1, delay=0, print_attempt=False)
|
||||||
|
|
@ -16,6 +33,26 @@ def main():
|
||||||
check_redis_socketio(retry=1, delay=0, print_attempt=False)
|
check_redis_socketio(retry=1, delay=0, print_attempt=False)
|
||||||
print("Redis SocketIO Connected")
|
print("Redis SocketIO Connected")
|
||||||
|
|
||||||
|
if(args.ping_services):
|
||||||
|
for service in args.ping_services:
|
||||||
|
service_name = None
|
||||||
|
service_port = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
service_name, service_port = service.split(':')
|
||||||
|
except ValueError:
|
||||||
|
print('Service should be in format host:port, e.g postgres:5432')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
check_service(
|
||||||
|
retry=1,
|
||||||
|
delay=0,
|
||||||
|
print_attempt=False,
|
||||||
|
service_name=service_name,
|
||||||
|
service_port=service_port,
|
||||||
|
)
|
||||||
|
print("{0}:{1} Connected".format(service_name, service_port))
|
||||||
|
|
||||||
print("Health check successful")
|
print("Health check successful")
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ elif [ "$1" = 'migrate' ]; then
|
||||||
elif [ "$1" = 'doctor' ]; then
|
elif [ "$1" = 'doctor' ]; then
|
||||||
|
|
||||||
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
|
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
|
||||||
&& python /home/frappe/frappe-bench/commands/doctor.py"
|
&& python /home/frappe/frappe-bench/commands/doctor.py ${@:2}"
|
||||||
exit
|
exit
|
||||||
|
|
||||||
elif [ "$1" = 'backup' ]; then
|
elif [ "$1" = 'backup' ]; then
|
||||||
|
|
|
||||||
|
|
@ -189,3 +189,17 @@ docker run \
|
||||||
```
|
```
|
||||||
|
|
||||||
Instead of `alpine` use any image of your choice.
|
Instead of `alpine` use any image of your choice.
|
||||||
|
|
||||||
|
## Health check
|
||||||
|
|
||||||
|
For socketio and gunicorn service ping the hostname:port and that will be sufficient. For workers and scheduler, there is a command that needs to be executed.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker exec -it <project-name>_erpnext-worker-d \
|
||||||
|
docker-entrypoint.sh doctor -p postgresql:5432 --ping-service mongodb:27017
|
||||||
|
```
|
||||||
|
|
||||||
|
Additional services can be pinged as part of health check with option `-p` or `--ping-service`.
|
||||||
|
|
||||||
|
This check ensures that given service should be connected along with services in common_site_config.json.
|
||||||
|
If connection to service(s) fails, the command fails with exit code 1.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue