Merge lp:~mvo/update-manager/use-screen-in-text-frontend into lp:update-manager

Proposed by Michael Vogt
Status: Merged
Merged at revision: 1979
Proposed branch: lp:~mvo/update-manager/use-screen-in-text-frontend
Merge into: lp:update-manager
Diff against target: 140 lines (+60/-23)
3 files modified
DistUpgrade/DistUpgradeMain.py (+43/-2)
DistUpgrade/DistUpgradeViewText.py (+14/-21)
DistUpgrade/screenrc (+3/-0)
To merge this branch: bzr merge lp:~mvo/update-manager/use-screen-in-text-frontend
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+42114@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

This branch will automatically use gnu screen if available to run the release upgrader inside a screen window called "ubuntu-release-upgrade-screen-window". If the terminal
goes away for some reason (e.g. network disconnect because of network problem or upgrade
problem) re-connecting and re-running the upgrade command will resume the upgrade.

For a admin running inside screen already nothing should change (except for the name of
the screen window) the command key will work normally. For a admin not using screen the
command key is disabled to avoid confusion with e.g. people used to emacs ctrl-a.

Zombie mode is enabled so that if the upgrade exits the screen content is still visible
for the admin to inspect.

Please let me know if there are any side effects I have not considered.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'DistUpgrade/DistUpgradeMain.py'
--- DistUpgrade/DistUpgradeMain.py 2010-06-09 12:20:44 +0000
+++ DistUpgrade/DistUpgradeMain.py 2010-11-29 14:07:21 +0000
@@ -88,6 +88,9 @@
88 # changes88 # changes
89 logging.info("Using config files '%s'" % config.config_files)89 logging.info("Using config files '%s'" % config.config_files)
90 logging.info("uname information: '%s'" % " ".join(os.uname()))90 logging.info("uname information: '%s'" % " ".join(os.uname()))
91 return logdir
92
93def save_system_state(logdir):
91 # save package state to be able to re-create failures94 # save package state to be able to re-create failures
92 system_files = []95 system_files = []
93 for f in [apt_pkg.Config.find_file("Dir::Etc::preferences"),96 for f in [apt_pkg.Config.find_file("Dir::Etc::preferences"),
@@ -109,7 +112,6 @@
109 open(os.path.join(logdir, "lspci.txt"), "w").write(s)112 open(os.path.join(logdir, "lspci.txt"), "w").write(s)
110 except OSError, e:113 except OSError, e:
111 logging.debug("lspci failed: %s" % e)114 logging.debug("lspci failed: %s" % e)
112 return logdir
113 115
114def setup_view(options, config, logdir):116def setup_view(options, config, logdir):
115 " setup view based on the config and commandline "117 " setup view based on the config and commandline "
@@ -132,14 +134,53 @@
132 sys.exit(1)134 sys.exit(1)
133 return instance135 return instance
134136
137def check_for_gnu_screen():
138 """ check if there is a upgrade already running inside gnu screen,
139 if so, reattach
140 if not, create new screen window
141 """
142 SCREENNAME = "ubuntu-release-upgrade-screen-window"
143 # get the active screen sockets
144 try:
145 out = subprocess.Popen(
146 ["screen","-ls"], stdout=subprocess.PIPE).communicate()[0]
147 logging.debug("screen returned: '%s'" % out)
148 except OSError:
149 logging.info("screen could not be run")
150 return
151 # check if a release upgrade is among them
152 if SCREENNAME in out:
153 logging.info("found active screen session, re-attaching")
154 # if we have it, attach to it
155 os.execv("/usr/bin/screen", ["screen", "-d", "-r", "-p", SCREENNAME])
156 # otherwise re-exec inside screen with (-L) for logging enabled
157 os.environ["RELEASE_UPGRADER_NO_SCREEN"]="1"
158 # unset escape key to avoid confusing people who are not used to
159 # screen. people who already run screen will not be affected by this
160 # unset escape key with -e, enable log with -L, set name with -S
161 cmd = ["screen",
162 "-e", "\\0\\0",
163 "-L",
164 "-c", "screenrc",
165 "-S", SCREENNAME]+sys.argv
166 logging.info("re-exec inside screen: '%s'" % cmd)
167 os.execv("/usr/bin/screen", cmd)
168
135def main():169def main():
136 " main method "170 """ main method """
137 171
138 # commandline setup and config172 # commandline setup and config
139 (options, args) = do_commandline()173 (options, args) = do_commandline()
140 config = DistUpgradeConfig(".")174 config = DistUpgradeConfig(".")
141 logdir = setup_logging(options, config)175 logdir = setup_logging(options, config)
142176
177 # gnu screen support
178 if not "RELEASE_UPGRADER_NO_SCREEN" in os.environ:
179 check_for_gnu_screen()
180
181 # save system state
182 save_system_state(logdir)
183
143 from DistUpgradeVersion import VERSION184 from DistUpgradeVersion import VERSION
144 logging.info("release-upgrader version '%s' started" % VERSION)185 logging.info("release-upgrader version '%s' started" % VERSION)
145186
146187
=== modified file 'DistUpgrade/DistUpgradeViewText.py'
--- DistUpgrade/DistUpgradeViewText.py 2010-11-26 17:07:20 +0000
+++ DistUpgrade/DistUpgradeViewText.py 2010-11-29 14:07:21 +0000
@@ -32,6 +32,7 @@
32import gettext32import gettext
33from DistUpgradeGettext import gettext as _33from DistUpgradeGettext import gettext as _
34from utils import wrap, twrap34from utils import wrap, twrap
35import subprocess
3536
36class TextFetchProgress(FetchProgress, apt.progress.TextFetchProgress):37class TextFetchProgress(FetchProgress, apt.progress.TextFetchProgress):
37 def __init__(self):38 def __init__(self):
@@ -79,29 +80,21 @@
79 self._installProgress = InstallProgress()80 self._installProgress = InstallProgress()
80 sys.excepthook = self._handleException81 sys.excepthook = self._handleException
81 #self._process_events_tick = 082 #self._process_events_tick = 0
82 #self._check_for_gnu_screen()
83
84 def _check_for_gnu_screen(self):
85 if (not "TERM" in os.environ or
86 not os.environ["TERM"] == "screen"):
87 self.information(_("Not running inside screen"),
88 _("Its recommended to run a server upgrade inside "
89 "the 'screen' environment."))
9083
91 def _handleException(self, type, value, tb):84 def _handleException(self, type, value, tb):
92 import traceback85 import traceback
93 print86 print
94 lines = traceback.format_exception(type, value, tb)87 lines = traceback.format_exception(type, value, tb)
95 logging.error("not handled exception:\n%s" % "\n".join(lines))88 logging.error("not handled exception:\n%s" % "\n".join(lines))
96 self.error(_("A fatal error occurred"),89 self.error(_("A fatal error occurred"),
97 _("Please report this as a bug and include the "90 _("Please report this as a bug and include the "
98 "files /var/log/dist-upgrade/main.log and "91 "files /var/log/dist-upgrade/main.log and "
99 "/var/log/dist-upgrade/apt.log "92 "/var/log/dist-upgrade/apt.log "
100 "in your report. The upgrade has aborted.\n"93 "in your report. The upgrade has aborted.\n"
101 "Your original sources.list was saved in "94 "Your original sources.list was saved in "
102 "/etc/apt/sources.list.distUpgrade."),95 "/etc/apt/sources.list.distUpgrade."),
103 "\n".join(lines))96 "\n".join(lines))
104 sys.exit(1)97 sys.exit(1)
10598
106 def getFetchProgress(self):99 def getFetchProgress(self):
107 return self._fetchProgress100 return self._fetchProgress
108101
=== added file 'DistUpgrade/screenrc'
--- DistUpgrade/screenrc 1970-01-01 00:00:00 +0000
+++ DistUpgrade/screenrc 2010-11-29 14:07:21 +0000
@@ -0,0 +1,3 @@
1logfile /var/log/dist-upgrade/screenlog.%n
2logtstamp on
3zombie xr
0\ No newline at end of file4\ No newline at end of file

Subscribers

People subscribed via source and target branches

to status/vote changes: