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

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

Issue 159753008: Disable Me2Me host controls on unsupported Linux systems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 IS_INSTALLED = (os.path.basename(sys.argv[0]) != 'me2me_virtual_host.py') 46 IS_INSTALLED = (os.path.basename(sys.argv[0]) != 'me2me_virtual_host.py')
47 47
48 if IS_INSTALLED: 48 if IS_INSTALLED:
49 HOST_BINARY_NAME = "chrome-remote-desktop-host" 49 HOST_BINARY_NAME = "chrome-remote-desktop-host"
50 else: 50 else:
51 HOST_BINARY_NAME = "remoting_me2me_host" 51 HOST_BINARY_NAME = "remoting_me2me_host"
52 52
53 CHROME_REMOTING_GROUP_NAME = "chrome-remote-desktop" 53 CHROME_REMOTING_GROUP_NAME = "chrome-remote-desktop"
54 54
55 CONFIG_DIR = os.path.expanduser("~/.config/chrome-remote-desktop")
56 HOME_DIR = os.environ["HOME"] 55 HOME_DIR = os.environ["HOME"]
56 CONFIG_DIR = HOME_DIR + "/.config/chrome-remote-desktop"
57 SESSION_FILE_PATH = HOME_DIR + "/.chrome-remote-desktop-session"
57 58
58 X_LOCK_FILE_TEMPLATE = "/tmp/.X%d-lock" 59 X_LOCK_FILE_TEMPLATE = "/tmp/.X%d-lock"
59 FIRST_X_DISPLAY_NUMBER = 20 60 FIRST_X_DISPLAY_NUMBER = 20
60 61
61 # Amount of time to wait between relaunching processes. 62 # Amount of time to wait between relaunching processes.
62 SHORT_BACKOFF_TIME = 5 63 SHORT_BACKOFF_TIME = 5
63 LONG_BACKOFF_TIME = 60 64 LONG_BACKOFF_TIME = 60
64 65
65 # How long a process must run in order not to be counted against the restart 66 # How long a process must run in order not to be counted against the restart
66 # thresholds. 67 # thresholds.
67 MINIMUM_PROCESS_LIFETIME = 60 68 MINIMUM_PROCESS_LIFETIME = 60
68 69
69 # Thresholds for switching from fast- to slow-restart and for giving up 70 # Thresholds for switching from fast- to slow-restart and for giving up
70 # trying to restart entirely. 71 # trying to restart entirely.
71 SHORT_BACKOFF_THRESHOLD = 5 72 SHORT_BACKOFF_THRESHOLD = 5
72 MAX_LAUNCH_FAILURES = SHORT_BACKOFF_THRESHOLD + 10 73 MAX_LAUNCH_FAILURES = SHORT_BACKOFF_THRESHOLD + 10
73 74
74 # Globals needed by the atexit cleanup() handler. 75 # Globals needed by the atexit cleanup() handler.
75 g_desktops = [] 76 g_desktops = []
76 g_host_hash = hashlib.md5(socket.gethostname()).hexdigest() 77 g_host_hash = hashlib.md5(socket.gethostname()).hexdigest()
77 78
79 def load_lsb_release_file():
80 result = {}
81 try:
82 for line in open('/etc/lsb-release').readlines():
83 parts = (line.split('#', 2)[0]).split('=', 2)
84 if len(parts) == 2:
85 result[parts[0].strip()] = parts[1].strip()
86 except IOError as e:
87 logging.error('Failed to load /etc/lsb-release: ' + str(e))
88 return result
89
90 def is_supported_platform():
91 # Always assume that the system is supported if the config directory or
92 # session file exist.
93 if os.path.isdir(CONFIG_DIR) or os.path.isfile(SESSION_FILE_PATH):
94 return True
95
96 # Currently the host supports only Goobuntu.
97 # TODO(sergeyu): Try other versions of Ubuntu and enable them here.
98 lsb_release = load_lsb_release_file()
99 return (lsb_release.has_key('GOOGLE_CODENAME') and
100 lsb_release['GOOGLE_CODENAME'] == 'precise')
101
78 class Config: 102 class Config:
79 def __init__(self, path): 103 def __init__(self, path):
80 self.path = path 104 self.path = path
81 self.data = {} 105 self.data = {}
82 self.changed = False 106 self.changed = False
83 107
84 def load(self): 108 def load(self):
85 """Loads the config from file. 109 """Loads the config from file.
86 110
87 Raises: 111 Raises:
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 A string containing the command to run, or a list of strings containing 519 A string containing the command to run, or a list of strings containing
496 the executable program and its arguments, which is suitable for passing as 520 the executable program and its arguments, which is suitable for passing as
497 the first parameter of subprocess.Popen(). If a suitable session cannot 521 the first parameter of subprocess.Popen(). If a suitable session cannot
498 be found, returns None. 522 be found, returns None.
499 """ 523 """
500 # If the session wrapper script (see below) is given a specific session as an 524 # If the session wrapper script (see below) is given a specific session as an
501 # argument (such as ubuntu-2d on Ubuntu 12.04), the wrapper will run that 525 # argument (such as ubuntu-2d on Ubuntu 12.04), the wrapper will run that
502 # session instead of looking for custom .xsession files in the home directory. 526 # session instead of looking for custom .xsession files in the home directory.
503 # So it's necessary to test for these files here. 527 # So it's necessary to test for these files here.
504 XSESSION_FILES = [ 528 XSESSION_FILES = [
505 "~/.chrome-remote-desktop-session", 529 SESSION_FILE_PATH,
506 "~/.xsession", 530 "~/.xsession",
507 "~/.Xsession" ] 531 "~/.Xsession" ]
508 for startup_file in XSESSION_FILES: 532 for startup_file in XSESSION_FILES:
509 startup_file = os.path.expanduser(startup_file) 533 startup_file = os.path.expanduser(startup_file)
510 if os.path.exists(startup_file): 534 if os.path.exists(startup_file):
511 # Use the same logic that a Debian system typically uses with ~/.xsession 535 # Use the same logic that a Debian system typically uses with ~/.xsession
512 # (see /etc/X11/Xsession.d/50x11-common_determine-startup), to determine 536 # (see /etc/X11/Xsession.d/50x11-common_determine-startup), to determine
513 # exactly how to run this file. 537 # exactly how to run this file.
514 if os.access(startup_file, os.X_OK): 538 if os.access(startup_file, os.X_OK):
515 # "/bin/sh -c" is smart about how to execute the session script and 539 # "/bin/sh -c" is smart about how to execute the session script and
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 "available (if the Xvfb server supports this).") 919 "available (if the Xvfb server supports this).")
896 parser.add_option("-f", "--foreground", dest="foreground", default=False, 920 parser.add_option("-f", "--foreground", dest="foreground", default=False,
897 action="store_true", 921 action="store_true",
898 help="Don't run as a background daemon.") 922 help="Don't run as a background daemon.")
899 parser.add_option("", "--start", dest="start", default=False, 923 parser.add_option("", "--start", dest="start", default=False,
900 action="store_true", 924 action="store_true",
901 help="Start the host.") 925 help="Start the host.")
902 parser.add_option("-k", "--stop", dest="stop", default=False, 926 parser.add_option("-k", "--stop", dest="stop", default=False,
903 action="store_true", 927 action="store_true",
904 help="Stop the daemon currently running.") 928 help="Stop the daemon currently running.")
929 parser.add_option("", "--get-status", dest="get_status", default=False,
930 action="store_true",
931 help="Prints host status")
905 parser.add_option("", "--check-running", dest="check_running", default=False, 932 parser.add_option("", "--check-running", dest="check_running", default=False,
906 action="store_true", 933 action="store_true",
907 help="Return 0 if the daemon is running, or 1 otherwise.") 934 help="Return 0 if the daemon is running, or 1 otherwise.")
908 parser.add_option("", "--config", dest="config", action="store", 935 parser.add_option("", "--config", dest="config", action="store",
909 help="Use the specified configuration file.") 936 help="Use the specified configuration file.")
910 parser.add_option("", "--reload", dest="reload", default=False, 937 parser.add_option("", "--reload", dest="reload", default=False,
911 action="store_true", 938 action="store_true",
912 help="Signal currently running host to reload the config.") 939 help="Signal currently running host to reload the config.")
913 parser.add_option("", "--add-user", dest="add_user", default=False, 940 parser.add_option("", "--add-user", dest="add_user", default=False,
914 action="store_true", 941 action="store_true",
915 help="Add current user to the chrome-remote-desktop group.") 942 help="Add current user to the chrome-remote-desktop group.")
916 parser.add_option("", "--host-version", dest="host_version", default=False, 943 parser.add_option("", "--host-version", dest="host_version", default=False,
917 action="store_true", 944 action="store_true",
918 help="Prints version of the host.") 945 help="Prints version of the host.")
919 (options, args) = parser.parse_args() 946 (options, args) = parser.parse_args()
920 947
921 # Determine the filename of the host configuration and PID files. 948 # Determine the filename of the host configuration and PID files.
922 if not options.config: 949 if not options.config:
923 options.config = os.path.join(CONFIG_DIR, "host#%s.json" % g_host_hash) 950 options.config = os.path.join(CONFIG_DIR, "host#%s.json" % g_host_hash)
924 951
925 # Check for a modal command-line option (start, stop, etc.) 952 # Check for a modal command-line option (start, stop, etc.)
953
954 if options.get_status:
955 pid = get_daemon_pid()
956 if pid != 0:
957 print "STARTED"
958 elif is_supported_platform():
959 print "STOPPED"
960 else:
961 print "NOT_IMPLEMENTED"
962 return 0
963
964 # TODO(sergeyu): Remove --check-running once NPAPI plugin and NM host are
965 # updated to always use get-status flag instead.
926 if options.check_running: 966 if options.check_running:
927 pid = get_daemon_pid() 967 pid = get_daemon_pid()
928 return 0 if pid != 0 else 1 968 return 0 if pid != 0 else 1
929 969
930 if options.stop: 970 if options.stop:
931 pid = get_daemon_pid() 971 pid = get_daemon_pid()
932 if pid == 0: 972 if pid == 0:
933 print "The daemon is not currently running" 973 print "The daemon is not currently running"
934 else: 974 else:
935 print "Killing process %s" % pid 975 print "Killing process %s" % pid
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 else: 1201 else:
1162 logging.info("Host exited with status %s." % os.WEXITSTATUS(status)) 1202 logging.info("Host exited with status %s." % os.WEXITSTATUS(status))
1163 elif os.WIFSIGNALED(status): 1203 elif os.WIFSIGNALED(status):
1164 logging.info("Host terminated by signal %s." % os.WTERMSIG(status)) 1204 logging.info("Host terminated by signal %s." % os.WTERMSIG(status))
1165 1205
1166 1206
1167 if __name__ == "__main__": 1207 if __name__ == "__main__":
1168 logging.basicConfig(level=logging.DEBUG, 1208 logging.basicConfig(level=logging.DEBUG,
1169 format="%(asctime)s:%(levelname)s:%(message)s") 1209 format="%(asctime)s:%(levelname)s:%(message)s")
1170 sys.exit(main()) 1210 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698