Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(814)

Side by Side Diff: remoting/tools/me2me_virtual_host.py

Issue 10825410: Update linux host to handle SIGHUP. use it to reload config. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/remoting.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # Virtual Me2Me implementation. This script runs and manages the processes 6 # Virtual Me2Me implementation. This script runs and manages the processes
7 # required for a Virtual Me2Me desktop, which are: X server, X desktop 7 # required for a Virtual Me2Me desktop, which are: X server, X desktop
8 # session, and Host process. 8 # session, and Host process.
9 # This script is intended to run continuously as a background daemon 9 # This script is intended to run continuously as a background daemon
10 # process, running under an ordinary (non-root) user account. 10 # process, running under an ordinary (non-root) user account.
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 642
643 for desktop in g_desktops: 643 for desktop in g_desktops:
644 if desktop.x_proc: 644 if desktop.x_proc:
645 logging.info("Terminating Xvfb") 645 logging.info("Terminating Xvfb")
646 desktop.x_proc.terminate() 646 desktop.x_proc.terminate()
647 647
648 648
649 def reload_config(): 649 def reload_config():
650 for desktop in g_desktops: 650 for desktop in g_desktops:
651 if desktop.host_proc: 651 if desktop.host_proc:
652 # Terminating the Host will cause the main loop to spawn another 652 desktop.host_proc.send_signal(signal.SIGHUP)
653 # instance, which will read any changes made to the Host config file.
654 desktop.host_proc.terminate()
655 653
656 654
657 def signal_handler(signum, stackframe): 655 def signal_handler(signum, stackframe):
658 if signum == signal.SIGUSR1: 656 if signum == signal.SIGHUP:
659 logging.info("SIGUSR1 caught, reloading configuration.") 657 logging.info("SIGHUP caught, reloading configuration.")
660 reload_config() 658 reload_config()
661 else: 659 else:
662 # Exit cleanly so the atexit handler, cleanup(), gets called. 660 # Exit cleanly so the atexit handler, cleanup(), gets called.
663 raise SystemExit 661 raise SystemExit
664 662
665 663
666 def main(): 664 def main():
667 DEFAULT_SIZE = "1280x800" 665 DEFAULT_SIZE = "1280x800"
668 parser = optparse.OptionParser( 666 parser = optparse.OptionParser(
669 "Usage: %prog [options] [ -- [ X server options ] ]") 667 "Usage: %prog [options] [ -- [ X server options ] ]")
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 print "The daemon currently is not running" 703 print "The daemon currently is not running"
706 else: 704 else:
707 print "Killing process %s" % pid 705 print "Killing process %s" % pid
708 os.kill(pid, signal.SIGTERM) 706 os.kill(pid, signal.SIGTERM)
709 return 0 707 return 0
710 708
711 if options.reload: 709 if options.reload:
712 running, pid = PidFile(pid_filename).check() 710 running, pid = PidFile(pid_filename).check()
713 if not running: 711 if not running:
714 return 1 712 return 1
715 os.kill(pid, signal.SIGUSR1) 713 os.kill(pid, signal.SIGHUP)
716 return 0 714 return 0
717 715
718 if not options.size: 716 if not options.size:
719 options.size = [DEFAULT_SIZE] 717 options.size = [DEFAULT_SIZE]
720 718
721 sizes = [] 719 sizes = []
722 for size in options.size: 720 for size in options.size:
723 size_components = size.split("x") 721 size_components = size.split("x")
724 if len(size_components) != 2: 722 if len(size_components) != 2:
725 parser.error("Incorrect size format '%s', should be WIDTHxHEIGHT" % size) 723 parser.error("Incorrect size format '%s', should be WIDTHxHEIGHT" % size)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 not auth_config_loaded or not auth.has_chromoting_credentials()) 789 not auth_config_loaded or not auth.has_chromoting_credentials())
792 need_register_host = not host_config_loaded 790 need_register_host = not host_config_loaded
793 # Outside the loop so user doesn't get asked twice. 791 # Outside the loop so user doesn't get asked twice.
794 if need_register_host: 792 if need_register_host:
795 host.ask_pin() 793 host.ask_pin()
796 elif options.new_pin or not host.is_pin_set(): 794 elif options.new_pin or not host.is_pin_set():
797 host.ask_pin() 795 host.ask_pin()
798 host.save_config(host_config) 796 host.save_config(host_config)
799 running, pid = PidFile(pid_filename).check() 797 running, pid = PidFile(pid_filename).check()
800 if running and pid != 0: 798 if running and pid != 0:
801 os.kill(pid, signal.SIGUSR1) 799 os.kill(pid, signal.SIGHUP)
802 print "The running instance has been updated with the new PIN." 800 print "The running instance has been updated with the new PIN."
803 return 0 801 return 0
804 802
805 # The loop is to deal with the case of registering a new Host with 803 # The loop is to deal with the case of registering a new Host with
806 # previously-saved auth tokens (from a previous run of this script), which 804 # previously-saved auth tokens (from a previous run of this script), which
807 # may require re-prompting for username & password. 805 # may require re-prompting for username & password.
808 while True: 806 while True:
809 if need_auth_tokens: 807 if need_auth_tokens:
810 try: 808 try:
811 auth.generate_tokens() 809 auth.generate_tokens()
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 desktop.launch_x_session() 899 desktop.launch_x_session()
902 900
903 if desktop.host_proc is None: 901 if desktop.host_proc is None:
904 logging.info("Launching host process") 902 logging.info("Launching host process")
905 desktop.launch_host(host_config) 903 desktop.launch_host(host_config)
906 904
907 try: 905 try:
908 pid, status = os.wait() 906 pid, status = os.wait()
909 except OSError, e: 907 except OSError, e:
910 if e.errno == errno.EINTR: 908 if e.errno == errno.EINTR:
911 # Retry on EINTR, which can happen if a signal such as SIGUSR1 is 909 # Retry on EINTR, which can happen if a signal such as SIGHUP is
912 # received. 910 # received.
913 continue 911 continue
914 else: 912 else:
915 # Anything else is an unexpected error. 913 # Anything else is an unexpected error.
916 raise 914 raise
917 915
918 logging.info("wait() returned (%s,%s)" % (pid, status)) 916 logging.info("wait() returned (%s,%s)" % (pid, status))
919 917
920 # When os.wait() notifies that a process has terminated, any Popen instance 918 # When os.wait() notifies that a process has terminated, any Popen instance
921 # for that process is no longer valid. Reset any affected instance to 919 # for that process is no longer valid. Reset any affected instance to
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 return 0 953 return 0
956 elif os.WEXITSTATUS(status) == 5: 954 elif os.WEXITSTATUS(status) == 5:
957 logging.info("Host domain is blocked by policy - exiting.") 955 logging.info("Host domain is blocked by policy - exiting.")
958 os.remove(host.config_file) 956 os.remove(host.config_file)
959 return 0 957 return 0
960 # Nothing to do for Mac-only status 6 (login screen unsupported) 958 # Nothing to do for Mac-only status 6 (login screen unsupported)
961 959
962 if __name__ == "__main__": 960 if __name__ == "__main__":
963 logging.basicConfig(level=logging.DEBUG) 961 logging.basicConfig(level=logging.DEBUG)
964 sys.exit(main()) 962 sys.exit(main())
OLDNEW
« no previous file with comments | « remoting/remoting.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698