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
1=== modified file 'DistUpgrade/DistUpgradeMain.py'
2--- DistUpgrade/DistUpgradeMain.py 2010-06-09 12:20:44 +0000
3+++ DistUpgrade/DistUpgradeMain.py 2010-11-29 14:07:21 +0000
4@@ -88,6 +88,9 @@
5 # changes
6 logging.info("Using config files '%s'" % config.config_files)
7 logging.info("uname information: '%s'" % " ".join(os.uname()))
8+ return logdir
9+
10+def save_system_state(logdir):
11 # save package state to be able to re-create failures
12 system_files = []
13 for f in [apt_pkg.Config.find_file("Dir::Etc::preferences"),
14@@ -109,7 +112,6 @@
15 open(os.path.join(logdir, "lspci.txt"), "w").write(s)
16 except OSError, e:
17 logging.debug("lspci failed: %s" % e)
18- return logdir
19
20 def setup_view(options, config, logdir):
21 " setup view based on the config and commandline "
22@@ -132,14 +134,53 @@
23 sys.exit(1)
24 return instance
25
26+def check_for_gnu_screen():
27+ """ check if there is a upgrade already running inside gnu screen,
28+ if so, reattach
29+ if not, create new screen window
30+ """
31+ SCREENNAME = "ubuntu-release-upgrade-screen-window"
32+ # get the active screen sockets
33+ try:
34+ out = subprocess.Popen(
35+ ["screen","-ls"], stdout=subprocess.PIPE).communicate()[0]
36+ logging.debug("screen returned: '%s'" % out)
37+ except OSError:
38+ logging.info("screen could not be run")
39+ return
40+ # check if a release upgrade is among them
41+ if SCREENNAME in out:
42+ logging.info("found active screen session, re-attaching")
43+ # if we have it, attach to it
44+ os.execv("/usr/bin/screen", ["screen", "-d", "-r", "-p", SCREENNAME])
45+ # otherwise re-exec inside screen with (-L) for logging enabled
46+ os.environ["RELEASE_UPGRADER_NO_SCREEN"]="1"
47+ # unset escape key to avoid confusing people who are not used to
48+ # screen. people who already run screen will not be affected by this
49+ # unset escape key with -e, enable log with -L, set name with -S
50+ cmd = ["screen",
51+ "-e", "\\0\\0",
52+ "-L",
53+ "-c", "screenrc",
54+ "-S", SCREENNAME]+sys.argv
55+ logging.info("re-exec inside screen: '%s'" % cmd)
56+ os.execv("/usr/bin/screen", cmd)
57+
58 def main():
59- " main method "
60+ """ main method """
61
62 # commandline setup and config
63 (options, args) = do_commandline()
64 config = DistUpgradeConfig(".")
65 logdir = setup_logging(options, config)
66
67+ # gnu screen support
68+ if not "RELEASE_UPGRADER_NO_SCREEN" in os.environ:
69+ check_for_gnu_screen()
70+
71+ # save system state
72+ save_system_state(logdir)
73+
74 from DistUpgradeVersion import VERSION
75 logging.info("release-upgrader version '%s' started" % VERSION)
76
77
78=== modified file 'DistUpgrade/DistUpgradeViewText.py'
79--- DistUpgrade/DistUpgradeViewText.py 2010-11-26 17:07:20 +0000
80+++ DistUpgrade/DistUpgradeViewText.py 2010-11-29 14:07:21 +0000
81@@ -32,6 +32,7 @@
82 import gettext
83 from DistUpgradeGettext import gettext as _
84 from utils import wrap, twrap
85+import subprocess
86
87 class TextFetchProgress(FetchProgress, apt.progress.TextFetchProgress):
88 def __init__(self):
89@@ -79,29 +80,21 @@
90 self._installProgress = InstallProgress()
91 sys.excepthook = self._handleException
92 #self._process_events_tick = 0
93- #self._check_for_gnu_screen()
94-
95- def _check_for_gnu_screen(self):
96- if (not "TERM" in os.environ or
97- not os.environ["TERM"] == "screen"):
98- self.information(_("Not running inside screen"),
99- _("Its recommended to run a server upgrade inside "
100- "the 'screen' environment."))
101
102 def _handleException(self, type, value, tb):
103- import traceback
104- print
105- lines = traceback.format_exception(type, value, tb)
106- logging.error("not handled exception:\n%s" % "\n".join(lines))
107- self.error(_("A fatal error occurred"),
108- _("Please report this as a bug and include the "
109- "files /var/log/dist-upgrade/main.log and "
110- "/var/log/dist-upgrade/apt.log "
111- "in your report. The upgrade has aborted.\n"
112- "Your original sources.list was saved in "
113- "/etc/apt/sources.list.distUpgrade."),
114- "\n".join(lines))
115- sys.exit(1)
116+ import traceback
117+ print
118+ lines = traceback.format_exception(type, value, tb)
119+ logging.error("not handled exception:\n%s" % "\n".join(lines))
120+ self.error(_("A fatal error occurred"),
121+ _("Please report this as a bug and include the "
122+ "files /var/log/dist-upgrade/main.log and "
123+ "/var/log/dist-upgrade/apt.log "
124+ "in your report. The upgrade has aborted.\n"
125+ "Your original sources.list was saved in "
126+ "/etc/apt/sources.list.distUpgrade."),
127+ "\n".join(lines))
128+ sys.exit(1)
129
130 def getFetchProgress(self):
131 return self._fetchProgress
132
133=== added file 'DistUpgrade/screenrc'
134--- DistUpgrade/screenrc 1970-01-01 00:00:00 +0000
135+++ DistUpgrade/screenrc 2010-11-29 14:07:21 +0000
136@@ -0,0 +1,3 @@
137+logfile /var/log/dist-upgrade/screenlog.%n
138+logtstamp on
139+zombie xr
140\ No newline at end of file

Subscribers

People subscribed via source and target branches

to status/vote changes: