Example #1
0
class MinionService(Service):
    def start(self):
        self.runflag = True
        self.log("Starting the Salt Minion")
        minion = salt.Minion()
        minion.start()
        while self.runflag:
            pass
            # self.sleep(10)
            # self.log("I'm alive ...")

    def stop(self):
        self.runflag = False
        self.log("Shutting down the Salt Minion")


if __name__ == "__main__":
    servicename = "salt-minion"
    try:
        status = win32serviceutil.QueryServiceStatus(servicename)
    except win32service.error as details:
        if details[0] == winerror.ERROR_SERVICE_DOES_NOT_EXIST:
            instart(MinionService, servicename, "Salt Minion")
            sys.exit(0)
    if status[1] == win32service.SERVICE_RUNNING:
        win32serviceutil.StopServiceWithDeps(servicename)
        win32serviceutil.StartService(servicename)
    else:
        win32serviceutil.StartService(servicename)
    def on_disconnect(self, ltr, disconnectEvents):
        self.log( "Disconnected: " + ltr )
        if( disconnectEvents[ltr] != "" ):
            self.log( "Running: " + disconnectEvents[ltr] )
            os.startfile(disconnectEvents[ltr]);

    def parse_config(self):
        base = win32serviceutil.GetServiceCustomOption('DriveLetterWatcher', 'startIn')
        jsonFile = json.load(file(base + "config.json.txt"))
        return jsonFile["connectEvents"], jsonFile["disconnectEvents"]
        
    def start(self):
        self.runflag = True
        old = self.get_drives()
        connectEvents, disconnectEvents = self.parse_config()
        while self.runflag:
            new = self.get_drives()
            for ltr in new.difference(old):
                self.on_connect(ltr, connectEvents)
            for ltr in old.difference(new):
                self.on_disconnect(ltr, disconnectEvents)
            old = new
            time.sleep(5)
            
    def stop(self):
        self.runflag = False
        
instart(DriveLetterWatcher, 'DriveLetterWatcher', 'DriveLetterWatcher')

Example #3
0
        print vhd_ext
        print vhd.get_best_supported_vhd_format()
        vhd.create_dynamic_vhd(ext_vhd_path, vhd_ext * (1024 ** 3), vhd.get_best_supported_vhd_format())

    vm.attach_ide_drive(name, root_image_path, 0, 0, constants.IDE_DISK)
    if vhd_ext and ext_vhd_path:
        vm.attach_ide_drive(name, ext_vhd_path, 0, 1, constants.IDE_DISK)
    nic_name = uuid.uuid4().get_hex()
    vm.create_nic(name, nic_name)
    net.connect_vnic_to_vswitch(VSWITCH_NAME, nic_name)

    vm.set_vm_state(name, constants.HYPERV_VM_STATE_ENABLED)
    return {
        "name": name,
        "cpu": cpu,
        "mem": mem,
        "disk": {"root": root_image_path, "ext": ext_vhd_path},
        "nic": nic_name,
    }


class BottleServer(Service):
    def start(self):
        run(app, host="0.0.0.0", port=8080)

    def stop(self):
        pass


instart(BottleServer, "bottleServer", "bottleServer")
Example #4
0
import sys

class MinionService(Service):
    def start(self):
        self.runflag=True
        self.log("Starting the Salt Minion")
        minion = salt.Minion()
        minion.start()
        while self.runflag:
            pass
            #self.sleep(10)
            #self.log("I'm alive ...")
    def stop(self):
        self.runflag=False
        self.log("Shutting down the Salt Minion")

if __name__ == '__main__':
    servicename = 'salt-minion'
    try:
        status = win32serviceutil.QueryServiceStatus(servicename)
    except win32service.error as details:
        if details[0]==winerror.ERROR_SERVICE_DOES_NOT_EXIST:
            instart(MinionService, servicename, 'Salt Minion')
            sys.exit(0)
    if status[1] == win32service.SERVICE_RUNNING:
        win32serviceutil.StopServiceWithDeps(servicename)
        win32serviceutil.StartService(servicename)
    else:
        win32serviceutil.StartService(servicename)

Example #5
0
        )
        print 'Start ok'
    except Exception, x:
        print str(x)

#
#
#
#
##### TEST MODULE
#
#
#
#

# winservice_test.py

from winservice import Service, instart

class Test(Service):
    def start(self):
        self.runflag=True
        while self.runflag:
            self.sleep(10)
            self.log("I'm alive ...")
    def stop(self):
        self.runflag=False
        self.log("I'm done")

instart(Test, 'aTest', 'Python Service Test')
Example #6
0
#
#
#
#
##### TEST MODULE
#
#
#
#

# winservice_test.py
from winservice import Service, instart
import subprocess
import os

class Test(Service):
    def start(self):
        path = os.getcwd() + "//Node.py"
        self.runflag=True
        subprocess.Popen(['python',path])
        while self.runflag:
            self.sleep(10)
            self.log("I'm alive ...")
    def stop(self):
        self.runflag=False
        self.log("I'm done")

instart(Test, 'aTestMe3', 'Python Service Test')
## end of http://code.activestate.com/recipes/551780/ }}}
Example #7
0
from winservice import Service, instart

import trustrouter.windows


class TrustRouterService(Service):
    def start(self):
        self.log("TrustRouter Started")
        self.runflag = True
        while self.runflag:
            self.log("TrustRouter Run")
            trustrouter.windows.run(self.log)

    def stop(self):
        self.runflag = False
        self.log("I'm done")


instart(TrustRouterService, 'TrustRouter',
        'Trust Router service that verifies Router Advertisments')
if log_filename is None:
   log_filename = getOption(svc_name, 'log_filename', None)

if prop_filename is None:
   print "Missing properties file name...quitting..."
   import servicemanager
   servicemanager.LogInfoMsg(str('Missing properties file name for service %s' % svc_name))
   sys.exit()
   
logging.config.fileConfig(log_filename)

logger = logging.getLogger('main_logger')

config_props=readProperties(prop_filename)
logger.debug( config_props )

http_address = ''
http_port = int(config_props["web.port"])

if nosvc:
   print ("Launching program at commandline")
   startServer()
else:
   instart(SiebelMgmtSvc, svc_name, svc_display_name)
   setOption(svc_name, 'prop_filename', prop_filename)
   setOption(svc_name, 'log_filename', log_filename)
   prop_filename = getOption(svc_name, 'prop_filename', None)
   log_filename = getOption(svc_name, 'log_filename', None)
   print ("Registered properties file name: %s" % (prop_filename))
   print ("Registered log file name: %s" % (log_filename))
Example #9
0
from winservice import Service, instart

import trustrouter.windows


class TrustRouterService(Service):
    def start(self):
        self.log("TrustRouter Started")
        self.runflag = True
        while self.runflag:
            self.log("TrustRouter Run")
            trustrouter.windows.run(self.log)

    def stop(self):
        self.runflag = False
        self.log("I'm done")


instart(TrustRouterService, "TrustRouter", "Trust Router service that verifies Router Advertisments")
Example #10
0
import sys


class MinionService(Service):
    def start(self):
        self.runflag=True
        self.log("Starting the Salt Minion")
        minion = salt.Minion()
        minion.start()
        while self.runflag:
            pass
            #self.sleep(10)
            #self.log("I'm alive ...")
    def stop(self):
        self.runflag=False
        self.log("Shutting down the Salt Minion")

if __name__ == '__main__':
    servicename = 'salt-minion'
    try:
        status = win32serviceutil.QueryServiceStatus(servicename)
    except win32service.error as details:
        if details[0] == winerror.ERROR_SERVICE_DOES_NOT_EXIST:
            instart(MinionService, servicename, 'Salt Minion')
            sys.exit(0)
    if status[1] == win32service.SERVICE_RUNNING:
        win32serviceutil.StopServiceWithDeps(servicename)
        win32serviceutil.StartService(servicename)
    else:
        win32serviceutil.StartService(servicename)