1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import time from oslo_service import service from oslo_config import cfg class MyService(service.Service): def __init__( self , conf = None ): self .conf = conf super (MyService, self ).__init__() def start( self ): print "service start...." time.sleep( 2 ) print "service end ...." def main(): conf = cfg.ConfigOpts() # 服务配置 server = MyService(conf) # 服务 launcher = service.launch(conf,server) # 启动服务 launcher.wait() # 服务启动后进程常驻 main() |
自定义服务,进程常驻,继承oslo_service 中service.Service类,实现其中start方法,使用service.lauch将进程拉起。上面是定义的一个简单的打印,模拟服务启动过程。