add updates-check support using uec-query-builds
This commit is contained in:
@@ -25,8 +25,10 @@ import subprocess
|
|||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
per_instance="once-per-instance"
|
per_instance="once-per-instance"
|
||||||
|
cronpre = "/etc/cron.d/cloudinit"
|
||||||
|
|
||||||
class CloudConfig():
|
class CloudConfig():
|
||||||
cfgfile = None
|
cfgfile = None
|
||||||
@@ -43,6 +45,7 @@ class CloudConfig():
|
|||||||
self.h_disable_ec2_metadata, "always")
|
self.h_disable_ec2_metadata, "always")
|
||||||
self.add_handler('config-mounts')
|
self.add_handler('config-mounts')
|
||||||
self.add_handler('config-puppet')
|
self.add_handler('config-puppet')
|
||||||
|
self.add_handler('config-misc')
|
||||||
|
|
||||||
def get_config_obj(self,cfgfile):
|
def get_config_obj(self,cfgfile):
|
||||||
f=file(cfgfile)
|
f=file(cfgfile)
|
||||||
@@ -184,6 +187,9 @@ class CloudConfig():
|
|||||||
|
|
||||||
send_ssh_keys_to_console()
|
send_ssh_keys_to_console()
|
||||||
|
|
||||||
|
def h_config_misc(self,name,args):
|
||||||
|
handle_updates_check(self.cfg)
|
||||||
|
|
||||||
def h_config_puppet(self,name,args):
|
def h_config_puppet(self,name,args):
|
||||||
# If there isn't a puppet key in the configuration don't do anything
|
# If there isn't a puppet key in the configuration don't do anything
|
||||||
if not self.cfg.has_key('puppet'): return
|
if not self.cfg.has_key('puppet'): return
|
||||||
@@ -463,3 +469,28 @@ def generate_sources_list(mirror):
|
|||||||
|
|
||||||
util.render_to_file('sources.list', '/etc/apt/sources.list', \
|
util.render_to_file('sources.list', '/etc/apt/sources.list', \
|
||||||
{ 'mirror' : mirror, 'codename' : codename })
|
{ 'mirror' : mirror, 'codename' : codename })
|
||||||
|
|
||||||
|
def handle_updates_check(cfg):
|
||||||
|
if not util.get_cfg_option_bool(cfg, 'updates-check', True):
|
||||||
|
return
|
||||||
|
build_info = "/etc/cloud/build.info"
|
||||||
|
if not os.path.isfile(build_info):
|
||||||
|
warn("no %s file" % build_info)
|
||||||
|
|
||||||
|
avail="%s/%s" % ( cloudinit.datadir, "available.build" )
|
||||||
|
cmd=( "uec-query-builds", "--system-suite", "--config", "%s" % build_info,
|
||||||
|
"--output", "%s" % avail, "is-update-available" )
|
||||||
|
try:
|
||||||
|
util.subp(cmd)
|
||||||
|
except:
|
||||||
|
warn("failed to execute uec-query-build for updates check")
|
||||||
|
|
||||||
|
# add a cron entry for this hour and this minute every day
|
||||||
|
try:
|
||||||
|
cron=open("%s-%s" % (cronpre, "updates") ,"w")
|
||||||
|
cron.write("%s root %s\n" % \
|
||||||
|
(time.strftime("%M %H * * * *"),' '.join(cmd)))
|
||||||
|
cron.close()
|
||||||
|
except:
|
||||||
|
warn("failed to enable cron update system check")
|
||||||
|
|
||||||
|
|||||||
35
tools/motd-hook
Executable file
35
tools/motd-hook
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# 92-ec2-upgrade-available - update-motd script
|
||||||
|
#
|
||||||
|
# Copyright (C) 2010 Canonical Ltd.
|
||||||
|
#
|
||||||
|
# Authors: Scott Moser <smoser@ubuntu.com>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, version 3 of the License.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
# Determining if updates are available is possibly slow.
|
||||||
|
# a cronjob runs occasioinally and updates a file with information
|
||||||
|
# on the latest available release (if newer than current)
|
||||||
|
|
||||||
|
BUILD_FILE=/var/lib/cloud/data/available.build
|
||||||
|
|
||||||
|
[ -s "${BUILD_FILE}" ] || exit 0
|
||||||
|
|
||||||
|
read suite build_name name serial < "${BUILD_FILE}"
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
A newer build of the Ubuntu ${suite} ${build_name} image is available.
|
||||||
|
It is named '${name}' and has build serial '${serial}'.
|
||||||
|
EOF
|
||||||
Reference in New Issue
Block a user