diff --git a/gravity/process_manager/supervisor_manager.py b/gravity/process_manager/supervisor_manager.py index 58aa5ba..3575097 100644 --- a/gravity/process_manager/supervisor_manager.py +++ b/gravity/process_manager/supervisor_manager.py @@ -3,6 +3,7 @@ import errno import os import shutil +import socket import subprocess import sys import time @@ -197,6 +198,8 @@ def __init__(self, state_dir=None, start_daemon=True, foreground=False): if not exists(self.supervisord_conf_dir): os.makedirs(self.supervisord_conf_dir) + self._check_path_length() + if start_daemon: self.__supervisord() @@ -226,6 +229,7 @@ def __supervisord(self): # any time that supervisord is not running, let's rewrite supervisord.conf open(self.supervisord_conf_path, "w").write(SUPERVISORD_CONF_TEMPLATE.format(**format_vars)) self.__supervisord_popen = subprocess.Popen(supervisord_cmd, env=os.environ) + rc = self.__supervisord_popen.poll() if rc: error("supervisord exited with code %d" % rc) @@ -243,6 +247,32 @@ def __get_supervisor(self): options.realize(args=["-c", self.supervisord_conf_path]) return supervisorctl.Controller(options).get_supervisor() + def _check_path_length(self): + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + bind_path = self.supervisord_sock_path + try: + os.unlink(bind_path) + sock.bind(bind_path) + except OSError as e: + if "AF_UNIX path too long" in str(e): + self._handle_socket_path_error() + else: + raise e + finally: + sock.close() + os.unlink(bind_path) + + def _handle_socket_path_error(self): + msg = f""" + The path to your gravity state directory is too long: "{self.supervisord_conf_dir}". + This path becomes part of a socket address. However, in Unix systems there is a limit to the + length of a socket file path (usually 103-108 bytes). You can choose another path with the + --state-dir option to the Gravity command, or by setting $GRAVITY_STATE_DIR in your + environment: + `galaxy --state-dir /home/shorter-path` or `$GRAVITY_STATE_DIR=/home/shorter-path ./run.sh` + """ + error(msg) + def terminate(self): if self.foreground: # if running in foreground, if terminate is called, then supervisord should've already received a SIGINT