예제 #1
0
    myname = node_reset_config['name']
        
    if not is_worker_thread_started():
      servicelogger.log("[WARN]:At " + str(time.time()) + " restarting worker...")
      start_worker_thread(configuration['pollfrequency'])

    if should_start_waitable_thread('advert','Advertisement Thread'):
      servicelogger.log("[WARN]:At " + str(time.time()) + " restarting advert...")
      start_advert_thread(vesseldict, myname, configuration['publickey'])

    if should_start_waitable_thread('status','Status Monitoring Thread'):
      servicelogger.log("[WARN]:At " + str(time.time()) + " restarting status...")
      start_status_thread(vesseldict,configuration['pollfrequency'])

    if not TEST_NM and not runonce.stillhaveprocesslock("seattlenodemanager"):
      servicelogger.log("[ERROR]:The node manager lost the process lock...")
      harshexit.harshexit(55)



    # Check for ip change.
    current_ip = None
    while True:
      try:
        current_ip = emulcomm.getmyip()
      except Exception, e:
        # If we aren't connected to the internet, emulcomm.getmyip() raises this:
        if len(e.args) >= 1 and e.args[0] == "Cannot detect a connection to the Internet.":
          # So we try again.
          pass
예제 #2
0
def main():
  """
  <Purpose>
    Has an infinite loop where we sleep for 5-55 minutes, then check for 
    updates.  If an update happens, we will restart ourselves and/or the
    node manager as necesary.
    
  <Arguments>
    None

  <Exceptions>
    Any non-RsyncError exceptions from do_rsync.

  <Side Effects>
    If there is an update on the update site we are checking, it will be 
    grabbed eventually.

  <Return>
    Will not return.  Either an exception will be thrown, we exit because we
    are restarting, or we loop infinitely.
  """

  global restartme

  # This is similar to init only:
  #   1) we loop / sleep
  #   2) we restart ourselves if we are updated
  #   3) we restart our client if they are updated

  while True:
    # sleep for 5-55 minutes 
    for junk in range(random.randint(10, 12)):
      # We need to wake up every 30 seconds otherwise we will take
      # the full 5-55 minutes before we die when someone tries to
      # kill us nicely.
      sleep(0.05)
      # Make sure we still have the process lock.
      # If not, we should exit
      if not runonce.stillhaveprocesslock('softwareupdater.old'):
        safe_log('[main] We no longer have the processlock\n')
        sys.exit(55)


    # Make sure that if we failed somehow to restart, we keep trying before
    # every time we try to update. - Brent
    if restartme:
      restart_software_updater()
      
    # where I'll put files...
    tempdir = tempfile.mkdtemp()+"/"

    tuf.interposition.refresh(configuration)

    # I'll clean this up in a minute
    try:
      updatedlist = do_rsync(softwareurl, "./",tempdir)
    except RsyncError:
      # oops, hopefully this will be fixed next time...
      continue

    finally:
      shutil.rmtree(tempdir)

    # no updates   :)   Let's wait again...
    if updatedlist == []:
      continue

    # if there were updates, the metainfo file should be one of them...
    assert('metainfo' in updatedlist)

    clientlist = updatedlist[:]

    if 'softwareupdater.py' in clientlist:
      restartme = True
      clientlist.remove('softwareupdater.py')

    # if the client software changed, let's update it!
    # AR: On Android, the native app takes care of starting/restarting 
    # the client and/or updater, depending on the exit code we return here.
    if clientlist != []:
      if not is_android:
        restart_client(clientlist)
      else:
        sys.exit(200) # Native app should restart both client and updater

    # oh! I've changed too.   I should restart...   search for MUTEX for info
    if restartme:
      if not is_android:
        restart_software_updater()
      else:
        sys.exit(201) # Native app should restart the updater
예제 #3
0
            node_reset_config['reset_accepter'] = True

        if not is_worker_thread_started():
            servicelogger.log("[WARN]:WorkerThread requires restart.")
            start_worker_thread(configuration['pollfrequency'])

        if should_start_waitable_thread('advert', 'Advertisement Thread'):
            servicelogger.log("[WARN]:AdvertThread requires restart.")
            start_advert_thread(vesseldict, myname, configuration['publickey'])

        if should_start_waitable_thread('status', 'Status Monitoring Thread'):
            servicelogger.log(
                "[WARN]:StatusMonitoringThread requires restart.")
            start_status_thread(vesseldict, configuration['pollfrequency'])

        if not TEST_NM and not runonce.stillhaveprocesslock(
                "seattlenodemanager"):
            servicelogger.log(
                "[ERROR]:The node manager lost the process lock...")
            harshexit.harshexit(55)

        # Check for IP address changes.
        # When using Affix, the NamingAndResolverAffix takes over this.
        if not affix_enabled:
            current_ip = None
            while True:
                try:
                    current_ip = emulcomm.getmyip()
                except Exception, e:
                    # If we aren't connected to the internet, emulcomm.getmyip() raises this:
                    if len(e.args) >= 1 and e.args[
                            0] == "Cannot detect a connection to the Internet.":
예제 #4
0
def main():
  """
  <Purpose>
    Has an infinite loop where we sleep for 5-55 minutes, then check for 
    updates.  If an update happens, we will restart ourselves and/or the
    node manager as necesary.
    
  <Arguments>
    None

  <Exceptions>
    Any non-RsyncError exceptions from do_rsync.

  <Side Effects>
    If there is an update on the update site we are checking, it will be 
    grabbed eventually.

  <Return>
    Will not return.  Either an exception will be thrown, we exit because we
    are restarting, or we loop infinitely.
  """

  global restartme

  # This is similar to init only:
  #   1) we loop / sleep
  #   2) we restart ourselves if we are updated
  #   3) we restart our client if they are updated

  while True:
    # sleep for 5-55 minutes 
    for junk in range(random.randint(10, 110)):
      # We need to wake up every 30 seconds otherwise we will take
      # the full 5-55 minutes before we die when someone tries to
      # kill us nicely.
      misc.do_sleep(30)
      # Make sure we still have the process lock.
      # If not, we should exit
      if not runonce.stillhaveprocesslock('softwareupdater.old'):
        safe_log('[main] We no longer have the processlock\n')
        sys.exit(55)


    # Make sure that if we failed somehow to restart, we keep trying before
    # every time we try to update. - Brent
    if restartme:
      restart_software_updater()
      
    # where I'll put files...
    tempdir = tempfile.mkdtemp()+"/"


    # I'll clean this up in a minute
    try:
      updatedlist = do_rsync(softwareurl, "./",tempdir)
    except RsyncError:
      # oops, hopefully this will be fixed next time...
      continue

    finally:
      shutil.rmtree(tempdir)

    # no updates   :)   Let's wait again...
    if updatedlist == []:
      continue

    # if there were updates, the metainfo file should be one of them...
    assert('metainfo' in updatedlist)

    clientlist = updatedlist[:]

    if 'softwareupdater.py' in clientlist:
      restartme = True
      clientlist.remove('softwareupdater.py')

    # if the client software changed, let's update it!
    # AR: On Android, the native app takes care of starting/restarting 
    # the client and/or updater, depending on the exit code we return here.
    if clientlist != []:
      if not is_android:
        restart_client(clientlist)
      else:
        sys.exit(200) # Native app should restart both client and updater

    # oh! I've changed too.   I should restart...   search for MUTEX for info
    if restartme:
      if not is_android:
        restart_software_updater()
      else:
        sys.exit(201) # Native app should restart the updater
예제 #5
0
runonce.getprocesslock(str(os.getpid()))

print "my process id is:"+str(os.getpid())
retval = runonce.getprocesslock(lockname)


if retval == True:
  print "I have the mutex"
elif retval == False:
  print "Another process has the mutex (owned by another user most likely)"
else:
  print "Process "+str(retval)+" has the mutex!"

while True:
  for num in range(random.randint(0,5)):
    time.sleep(2)
    if runonce.stillhaveprocesslock(lockname):
      print "I have the mutex"
    else:
      print "I do not have the mutex"
    if runonce.stillhaveprocesslock(str(os.getpid())):
      print "I have my mutex"
    else:
      print "I do not have my mutex"


  time.sleep(2)
  print "releasing mutex (if possible)"
  runonce.releaseprocesslock(lockname)

예제 #6
0
lockname = "seattletestlock"

runonce.getprocesslock(str(os.getpid()))

print "my process id is:" + str(os.getpid())
retval = runonce.getprocesslock(lockname)

if retval == True:
    print "I have the mutex"
elif retval == False:
    print "Another process has the mutex (owned by another user most likely)"
else:
    print "Process " + str(retval) + " has the mutex!"

while True:
    for num in range(random.randint(0, 5)):
        time.sleep(2)
        if runonce.stillhaveprocesslock(lockname):
            print "I have the mutex"
        else:
            print "I do not have the mutex"
        if runonce.stillhaveprocesslock(str(os.getpid())):
            print "I have my mutex"
        else:
            print "I do not have my mutex"

    time.sleep(2)
    print "releasing mutex (if possible)"
    runonce.releaseprocesslock(lockname)
def main(debug=False):
  """
  <Purpose>
    Has an infinite loop where we sleep for 5-55 minutes, then check for 
    updates.  If an update happens, we will restart ourselves and/or the
    node manager as necesary.
    
  <Arguments>
    None

  <Exceptions>
    Any non-RsyncError exceptions from do_rsync.

  <Side Effects>
    If there is an update on the update site we are checking, it will be 
    grabbed eventually.

  <Return>
    Will not return.  Either an exception will be thrown, we exit because we
    are restarting, or we loop infinitely.
  """

  global restartme

  # This is similar to init only:
  #   1) we loop / sleep
  #   2) we restart ourselves if we are updated
  #   3) we restart our client if they are updated

  while True:
    if debug:
      rint = 1
    else:
      rint = random.randint(10, 110)
    for junk in range(rint):
      # We need to wake up every 30 seconds otherwise we will take
      # the full 5-55 minutes before we die when someone tries to
      # kill us nicely.
      misc.do_sleep(1)
      # Make sure we still have the process lock.
      # If not, we should exit
      if not runonce.stillhaveprocesslock('softwareupdater.old'):
        safe_log('[main] We no longer have the processlock\n')
        sys.exit(55)

    # set the softwareurl based on whether debug is set
    if debug:
      softwareurl = 'http://localhost:12345'
    else:
      softwareurl = seattle_url

    # Make sure that if we failed somehow to restart, we keep trying before
    # every time we try to update. - Brent
    if restartme:
      restart_software_updater()
      
    # where I'll put files...
    tempdir = tempfile.mkdtemp()+"/"


    # I'll clean this up in a minute
    try:
      updatedlist = do_rsync(softwareurl, "./",tempdir)
    except Exception:
      safe_log_last_exception()
      # oops, hopefully this will be fixed next time...
      continue

    finally:
      shutil.rmtree(tempdir)

    safe_log('[main] rsync with server yielded the following changes: %s' % str(updatedlist))
    # no updates   :)   Let's wait again...
    if updatedlist == []:
      continue

    clientlist = updatedlist[:]
    if 'softwareupdater.py' in clientlist:
      restartme = True
      clientlist.remove('softwareupdater.py')

    # if the client software changed, let's update it!
    if clientlist != []:
      restart_client(clientlist)

    # oh! I've changed too.   I should restart...   search for MUTEX for info
    if restartme:
      restart_software_updater()

    if debug: break
예제 #8
0
def main(debug=False):
  """
  <Purpose>
    Has an infinite loop where we sleep for 5-55 minutes, then check for 
    updates.  If an update happens, we will restart ourselves and/or the
    node manager as necesary.
    
  <Arguments>
    None

  <Exceptions>
    Any non-RsyncError exceptions from do_rsync.

  <Side Effects>
    If there is an update on the update site we are checking, it will be 
    grabbed eventually.

  <Return>
    Will not return.  Either an exception will be thrown, we exit because we
    are restarting, or we loop infinitely.
  """

  global restartme

  # This is similar to init only:
  #   1) we loop / sleep
  #   2) we restart ourselves if we are updated
  #   3) we restart our client if they are updated

  while True:
    if debug:
      rint = 1
    else:
      rint = random.randint(10, 110)
    for junk in range(rint):
      # We need to wake up every 30 seconds otherwise we will take
      # the full 5-55 minutes before we die when someone tries to
      # kill us nicely.
      misc.do_sleep(1)
      # Make sure we still have the process lock.
      # If not, we should exit
      if not runonce.stillhaveprocesslock('softwareupdater.old'):
        safe_log('[main] We no longer have the processlock\n')
        sys.exit(55)

    # set the softwareurl based on whether debug is set
    if debug:
      softwareurl = 'http://localhost:12345'
    else:
      softwareurl = seattle_url

    # Make sure that if we failed somehow to restart, we keep trying before
    # every time we try to update. - Brent
    if restartme:
      restart_software_updater()
      
    # where I'll put files...
    tempdir = tempfile.mkdtemp()+"/"


    # I'll clean this up in a minute
    try:
      updatedlist = do_rsync(softwareurl, "./",tempdir)
    except Exception:
      safe_log_last_exception()
      # oops, hopefully this will be fixed next time...
      continue

    finally:
      shutil.rmtree(tempdir)

    safe_log('[main] rsync with server yielded the following changes: %s' % str(updatedlist))
    # no updates   :)   Let's wait again...
    if updatedlist == []:
      continue

    clientlist = updatedlist[:]
    if 'softwareupdater.py' in clientlist:
      restartme = True
      clientlist.remove('softwareupdater.py')

    # if the client software changed, let's update it!
    if clientlist != []:
      restart_client(clientlist)

    # oh! I've changed too.   I should restart...   search for MUTEX for info
    if restartme:
      restart_software_updater()

    if debug: break