Skip to content

Commit

Permalink
refactor: Simplify supervisor socket path configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Alok Singh <[email protected]>
  • Loading branch information
Xieyt committed Jan 30, 2025
1 parent 0bf5951 commit 69adbd0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Docker/frappe/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ echo "Setting up user"

update_uid_gid "${USERID}" "${USERGROUP}" "frappe" "frappe"

SOCK_DIR='/workspace/frappe-bench/config/fm-supervisord-sockets'
SOCK_DIR='/fm-sockets'
SOCK_SERVICE_PATH="$SOCK_DIR/$SERVICE_NAME.sock"

echo "Setting supervisord sock directory to $SOCK_SERVICE_PATH"
Expand All @@ -33,7 +33,7 @@ mkdir -p /opt/user/conf.d $SOCK_DIR
chown "$USERID:$USERGROUP" $SOCK_DIR /opt/user/conf.d
rm -rf "$SOCK_SERVICE_PATH"

sed -i "s/\opt\/user\/supervisor\.sock/workspace\/frappe-bench\/config\/fm-supervisord-sockets\/${SERVICE_NAME}\.sock/g" /opt/user/supervisord.conf
sed -i "s/\opt\/user\/supervisor\.sock/fm-sockets\/${SERVICE_NAME}\.sock/g" /opt/user/supervisord.conf
echo "supervisord configured $?"

if [ "$#" -gt 0 ]; then
Expand Down
2 changes: 1 addition & 1 deletion Docker/frappe/fm_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

FM_SUPERVISOR_SOCKETS_DIR = Path(
os.environ.get(
"SUPERVISOR_SOCKET_DIR", "/workspace/frappe-bench/config/fm-supervisord-sockets"
"SUPERVISOR_SOCKET_DIR", "/fm-sockets"
)
)

Expand Down
5 changes: 1 addition & 4 deletions frappe_manager/compose_manager/ComposeFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,8 @@ def set_root_volumes_names(self, volume_prefix: str) -> None:
if volumes[volume_name] is None:
volumes[volume_name] = {}

# Replace hyphens in volume name with the site name delimiter
formatted_name = volume_name.replace('-', CLI_SITE_NAME_DELIMETER)

# Set the volume name with prefix
volumes[volume_name]['name'] = volume_prefix + CLI_DEFAULT_DELIMETER + formatted_name
volumes[volume_name]['name'] = volume_prefix + CLI_DEFAULT_DELIMETER + volume_name

except KeyError as e:
richprint.warning(f"Error setting volume names: {str(e)}")
Expand Down
24 changes: 14 additions & 10 deletions frappe_manager/site_manager/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ def switch_bench_env(self, timeout: int = 30, interval: int = 1):
if not self.is_supervisord_running():
raise BenchFrappeServiceSupervisorNotRunning(self.name)

frappe_workspace_path: str = "workspace/frappe-bench/config/fm-supervisord-sockets/frappe.sock"
frappe_workspace_path: str = "/fm-sockets/frappe.sock"
frappe_supervisor_socket_location = self.path / frappe_workspace_path

supervisorctl_command = f"supervisorctl -s unix:///{frappe_workspace_path} "
Expand Down Expand Up @@ -1285,18 +1285,24 @@ def reset(self, admin_password: Optional[str] = None):
def restart_supervisor_service(
self, service: str, compose_project_obj: Optional[ComposeProject] = None, timeout: int = 30, interval: int = 1
):
supervisor_socket_location = (
self.path / "workspace/frappe-bench/config/fm-supervisord-sockets" / f"{service}.sock"
)
socket_path = f"/fm-sockets/{service}.sock"

# Wait for supervisor socket file to be created
# Wait for supervisor socket file to be created in container
for _ in range(timeout):
if supervisor_socket_location.exists():
try:
# Use ls command to check if file exists in container
self.compose_project.docker.compose.exec(
service=service,
command=f"test -e {socket_path}",
stream=False
)
break
time.sleep(interval)
except DockerException:
time.sleep(interval)
else:
raise BenchOperationException(
self.name, message=f'Supervisor socket for {service} service not created after {timeout} seconds'
self.name,
message=f'Supervisor socket for {service} service not created after {timeout} seconds'
)

restart_supervisor_command = 'supervisorctl -c /opt/user/supervisord.conf restart all'
Expand Down Expand Up @@ -1326,8 +1332,6 @@ def restart_web_containers_services(self):
SiteServicesEnum.socketio.value,
]

restart_supervisor_command = 'supervisorctl -c /opt/user/supervisord.conf restart all'

for service in web_services:
richprint.change_head(f"Restarting web services - {service}")
is_restarted = self.restart_supervisor_service(service)
Expand Down
5 changes: 5 additions & 0 deletions frappe_manager/templates/docker-compose.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
USERGROUP: REPLACE_ME_WITH_CURRENT_USER_GROUP
SERVICE_NAME: frappe
volumes:
- fm-sockets:/fm-sockets
- ./workspace:/workspace
expose:
- 80
Expand Down Expand Up @@ -49,6 +50,7 @@ services:
- 80
command: launch_supervisor_service.sh
volumes:
- fm-sockets:/fm-sockets
- ./workspace:/workspace
networks:
site-network:
Expand All @@ -62,6 +64,7 @@ services:
SERVICE_NAME: schedule
command: launch_supervisor_service.sh
volumes:
- fm-sockets:/fm-sockets
- ./workspace:/workspace
networks:
site-network:
Expand Down Expand Up @@ -98,6 +101,8 @@ services:
site-network:

volumes:
fm-sockets:
name: fm__SITE_NAME_PREFIX__fm-sockets
redis-socketio-data:
name: fm__SITE_NAME_PREFIX__redis-socketio-data
redis-queue-data:
Expand Down
5 changes: 5 additions & 0 deletions frappe_manager/templates/docker-compose.workers.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ services:
site-network:
global-backend-network:
volumes:
- fm-sockets:/fm-sockets
- ./workspace:/workspace
environment:
USERID: REPLACE_ME_WITH_CURRENT_USER
USERGROUP: REPLACE_ME_WITH_CURRENT_USER_GROUP
SERVICE_NAME: worker-name

volumes:
fm-sockets:
name: fm__SITE_NAME_PREFIX__fm-sockets

networks:
site-network:
name: fm__SITE_NAME_PREFIX__site-network
Expand Down

0 comments on commit 69adbd0

Please sign in to comment.