@@ -491,6 +491,23 @@ def get_filename_from_url(url):
491491 from urllib .parse import urlparse
492492 return os .path .basename (urlparse (url ).path .rstrip ("/" ))
493493
494+ def kill_process (name ):
495+ # Ask user for the name of process
496+ import os , signal
497+ try :
498+ # iterating through each instance of the process
499+ for line in os .popen (f'ps ax | grep "usr/bin/{ name } " | grep -v grep' ):
500+ fields = line .split ()
501+
502+ # extracting Process ID from the output
503+ pid = fields [0 ]
504+
505+ # terminating process
506+ os .kill (int (pid ), signal .SIGKILL )
507+ print ("Killing" ,pid )
508+ except :
509+ print ("Error Encountered while running script" )
510+
494511def install_desktop_app_in_vm (
495512 debian_installer_url ,
496513 port ,
@@ -514,7 +531,8 @@ def install_desktop_app_in_vm(
514531
515532 subprocess .run (["wget" , debian_installer_url ], check = True , stderr = subprocess .STDOUT )
516533 package_name = subprocess .check_output (f"dpkg-deb -f ./{ default_name } Package" , shell = True ).decode ().strip ()
517- if is_package_installed (package_name ):
534+ is_already_installed = is_package_installed (package_name )
535+ if is_already_installed :
518536 install_command = f"sudo dpkg -i ./{ default_name } "
519537 else :
520538 install_command = f"sudo apt --fix-broken install ./{ default_name } -y"
@@ -547,15 +565,14 @@ def install_desktop_app_in_vm(
547565User={ uname }
548566Environment="DISPLAY=:99"
549567ExecStart=/usr/bin/{ package_name } --only-start-api --port { port } { '--api-base-path ' + api_base_path if api_base_path else '' }
550- Restart=on-failure
551- RestartSec=10
568+ Restart=always
569+ RestartSec=1
552570[Install]
553571WantedBy=multi-user.target"""
554572 write_file_sudo (package_service_content , f"/etc/systemd/system/{ package_service_name } " )
555573
556574 if not skip_apache_request_routing :
557575 setup_apache_load_balancer_desktop_app (port , api_base_path )
558-
559576 # Enable and start services
560577 systemctl_commands = f"""
561578sudo systemctl daemon-reload
@@ -570,6 +587,9 @@ def install_desktop_app_in_vm(
570587sudo systemctl restart apache2"""
571588 subprocess .run (remove_empty_lines (systemctl_commands ), shell = True , check = True , stderr = subprocess .STDOUT )
572589
590+ if is_already_installed :
591+ kill_process (package_name )
592+
573593 click .echo ("Successfully installed the Desktop App." )
574594 click .echo ("Now, Checking API Status..." )
575595
0 commit comments