amazon ec2 - Update python itself using the apt module -


i writing python script run on ec2 machine user-data-script. i'm trying figure out how can upgrade packages on machine similar bash command:

$ sudo apt-get -qqy update && sudo apt-get -qqy upgrade 

i know can use apt package in python this:

import apt cache=apt.cache() cache.update() cache.open(none) cache.upgrade() cache.commit() 

problem happens if python 1 of packages upgraded. there way reload interpreter , script following upgrade , continue left off?

right choice use shell script user-data script sole purpose of upgrading packages (including possibly python) , dropping python rest of code. i'd eliminate step of using shell script.

i think figured out:

def main():     import argparse     parser = argparse.argumentparser(description='user-data-script.py: initial python instance startup script')     parser.add_argument('--skip-update', default=false, action='store_true', help='skip apt package updates')     # parser.add_argument whatever else need     args = parser.parse_args()      if not args.skip_update:         # update         import apt         cache = apt.cache()         cache.update()         cache.open(none)         cache.upgrade()         cache.commit()          # restart, , skip update         import os, sys         command = sys.argv[0]         args = sys.argv         if skipupdate:             args += ['--skip-update']         os.execv(command, args)      else:         # run usual code         pass  if __name__ == '__main__':     main() 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -