@@ -325,8 +325,8 @@ def migrate(c: Connection | DockerRunner | Context, config: dict) -> None:
325325 try :
326326 # Execute real migration command
327327 c .run (
328- f"source { deploy_path } /{ venv_path } /bin/activate && "
329- f"cd { deploy_path } && python manage.py migrate" ,
328+ f"bash -c ' source { deploy_path } /{ venv_path } /bin/activate && "
329+ f"cd { deploy_path } && python manage.py migrate' " ,
330330 pty = True
331331 )
332332
@@ -337,19 +337,22 @@ def migrate(c: Connection | DockerRunner | Context, config: dict) -> None:
337337 raise DeployerException (msg_raise ) from e
338338
339339 logger .info ("Running Django db_seed..." )
340- try :
341- # Execute real migration command
342- c .run (
343- f"bash -c 'source { deploy_path } /{ venv_path } /bin/activate && "
344- f"cd { deploy_path } && python manage.py db_seed "
345- f"> /dev/null 2>&1'" ,
346- pty = True
347- )
348- except DeployerException as e :
349- # Handle any exception during migration
350- logger .error ("Seed execution failed." )
351- msg_raise = f"Seed error: { e !s} "
352- raise DeployerException (msg_raise ) from e
340+ # Execute db_seed command with visible output for debugging
341+ result = c .run (
342+ f"bash -c 'source { deploy_path } /{ venv_path } /bin/activate && "
343+ f"cd { deploy_path } && python manage.py db_seed'" ,
344+ pty = True ,
345+ warn = True
346+ )
347+
348+ # Check if db_seed failed
349+ if result and result .failed :
350+ logger .error ("db_seed command failed." )
351+ output = getattr (result , "stdout" , "" ).strip ()
352+ if output :
353+ logger .error (f"Error output:\n { output } " )
354+ msg_raise = "db_seed execution failed."
355+ raise DeployerException (msg_raise )
353356
354357def collect_static (
355358 c : Connection | DockerRunner | Context ,
@@ -391,11 +394,11 @@ def restart_services(
391394 config : dict
392395 ) -> None :
393396 """
394- Start or restart Gunicorn and Celery workers for the project.
397+ Start or restart services for the project using Procfile configuration .
395398
396- Uses the bash scripts 'start_gunicorn_supervisord .sh' and
397- 'start_celery_supervisord.sh' to handle the restart process.
398- If either script doesn't exist, logs a warning and continues.
399+ Uses the bash script 'start_procfile_supervisord .sh' to handle the
400+ restart process.
401+ If the script doesn't exist, logs a warning and continues.
399402
400403 :param c: Fabric runner or connection object.
401404 :type c: Union[Connection, DockerRunner, Context]
@@ -408,94 +411,48 @@ def restart_services(
408411 # Get site name from config
409412 site = config ['name' ]
410413
411- # Define script paths
412- gunicorn_script_path = "/scripts/start_gunicorn_supervisord.sh"
413- celery_script_path = "/scripts/start_celery_supervisord.sh"
414+ # Define script path
415+ procfile_script_path = "/scripts/start_procfile_supervisord.sh"
414416
415- # First, restart Gunicorn services
416- # Check if the Gunicorn script exists
417- check_gunicorn_script = c .run (
418- f"test -f { gunicorn_script_path } && echo 'exists' || echo 'not_found'" ,
417+ # Check if the Procfile script exists
418+ check_script = c .run (
419+ f"test -f { procfile_script_path } && echo 'exists' || echo 'not_found'" ,
419420 hide = True ,
420421 warn = True
421422 )
422- if check_gunicorn_script is None :
423+ if check_script is None :
423424 logger .warning (
424- f"Script { gunicorn_script_path } not found. "
425- f"Skipping Gunicorn restart."
425+ f"Script { procfile_script_path } not found. "
426+ f"Skipping services restart."
426427 )
427428 else :
428- gunicorn_script_exists = (
429- check_gunicorn_script .stdout .strip () == "exists"
430- )
431-
432- if not gunicorn_script_exists :
433- logger .warning (
434- f"Script { gunicorn_script_path } not found. "
435- f"Skipping Gunicorn restart."
436- )
437- else :
438- logger .info (f"Restarting Gunicorn services for { site } ..." )
439-
440- # Determine if we should restart a specific site or all sites
441- if site and site != "all" :
442- # Restart specific site
443- result = c .run (f"{ gunicorn_script_path } { site } " , warn = True )
444- else :
445- # Restart all sites
446- result = c .run (f"{ gunicorn_script_path } " , warn = True )
447-
448- # Check if the command executed successfully
449- if result and not result .failed :
450- logger .info (
451- f"Gunicorn services for { site } restarted successfully"
452- )
453- else :
454- logger .error (f"Failed to restart Gunicorn services for { site } " )
455- error_details = (
456- result .stderr if result and hasattr (result , 'stderr' )
457- else 'Unknown error'
458- )
459- logger .error (f"Error details: { error_details } " )
460-
461- # Second, restart Celery workers
462- # Check if the Celery script exists
463- check_celery_script = c .run (
464- f"test -f { celery_script_path } && echo 'exists' || echo 'not_found'" ,
465- hide = True ,
466- warn = True
467- )
468- if check_celery_script is None :
469- logger .warning (
470- f"Script { celery_script_path } not found. "
471- f"Skipping Celery workers restart."
429+ script_exists = (
430+ check_script .stdout .strip () == "exists"
472431 )
473- else :
474- celery_script_exists = check_celery_script .stdout .strip () == "exists"
475432
476- if not celery_script_exists :
433+ if not script_exists :
477434 logger .warning (
478- f"Script { celery_script_path } not found. "
479- f"Skipping Celery workers restart."
435+ f"Script { procfile_script_path } not found. "
436+ f"Skipping services restart."
480437 )
481438 else :
482- logger .info (f"Restarting Celery workers for { site } ..." )
439+ logger .info (f"Restarting services for { site } ..." )
483440
484441 # Determine if we should restart a specific site or all sites
485442 if site and site != "all" :
486443 # Restart specific site
487- result = c .run (f"{ celery_script_path } { site } " , warn = True )
444+ result = c .run (f"{ procfile_script_path } { site } " , warn = True )
488445 else :
489446 # Restart all sites
490- result = c .run (f"{ celery_script_path } " , warn = True )
447+ result = c .run (f"{ procfile_script_path } " , warn = True )
491448
492449 # Check if the command executed successfully
493450 if result and not result .failed :
494451 logger .info (
495- f"Celery workers for { site } restarted successfully"
452+ f"Services for { site } restarted successfully"
496453 )
497454 else :
498- logger .error (f"Failed to restart Celery workers for { site } " )
455+ logger .error (f"Failed to restart services for { site } " )
499456 error_details = (
500457 result .stderr if result and hasattr (result , 'stderr' )
501458 else 'Unknown error'
@@ -594,6 +551,20 @@ def create_backup(
594551 logger .warning (msg )
595552 return
596553
554+ # Verify that the symlink points to a valid directory
555+ target_check = c .run (
556+ f"test -d { deploy_path } /current && echo 'valid'" ,
557+ hide = True , warn = True
558+ )
559+
560+ if (not target_check or not target_check .ok or
561+ target_check .stdout .strip () != 'valid' ):
562+ msg = (
563+ "Skipping backup: Current symlink points to invalid directory."
564+ )
565+ logger .warning (msg )
566+ return
567+
597568 logger .info (
598569 f"Creating backup for site '{ site_name } ' at { backup_file } "
599570 )
@@ -609,10 +580,18 @@ def create_backup(
609580 try :
610581 # Get the current release name
611582 result = c .run (
612- f"basename $(readlink { deploy_path } /current)" ,
613- hide = True
583+ f"readlink { deploy_path } /current | xargs basename" ,
584+ hide = True ,
585+ warn = True
614586 )
615- release_name = result .stdout .strip () if result else ""
587+ release_name = result .stdout .strip () if result and result .ok else ""
588+
589+ if not release_name :
590+ logger .warning (
591+ "Could not determine current release name. "
592+ "Skipping backup."
593+ )
594+ return
616595
617596 # Backup only the current release
618597 c .run (
0 commit comments