def main(argv): # Check SMF invocation environment if os.getenv("SMF_FMRI") == None or os.getenv("SMF_METHOD") != "start": sys.stderr.write("Command line invocation of %s unsupported.\n" \ % (sys.argv[0])) sys.stderr.write( "This command is intended for smf(5) invocation only.\n") sys.exit(smf.SMF_EXIT_ERR_NOSMF) # Daemonise the service. create_daemon() # The user security attributes checked are the following: # Note that UID == 0 will match any profile search so # no need to check it explicitly. syslog.openlog("time-sliderd", 0, syslog.LOG_DAEMON) rbacp = RBACprofile() if rbacp.has_profile("ZFS File System Management"): gobject.threads_init() # Tell dbus to use the gobject mainloop for async ops dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) dbus.mainloop.glib.threads_init() # Register a bus name with the system dbus daemon systemBus = dbus.SystemBus() name = dbus.service.BusName("org.opensolaris.TimeSlider", systemBus) # Create and start the snapshot manger. Takes care of # auto snapshotting service and auto cleanup. snapshot = SnapshotManager(systemBus) snapshot.start() gobject.timeout_add(2000, monitor_threads, snapshot) mainloop = gobject.MainLoop() try: mainloop.run() except KeyboardInterrupt: mainloop.quit() sys.exit(smf.SMF_EXIT_OK) else: syslog.syslog(syslog.LOG_ERR, "%s has insufficient privileges to run time-sliderd!" \ % rbacp.name) syslog.closelog() sys.exit(smf.SMF_EXIT_ERR_PERM) syslog.closelog() sys.exit(smf.SMF_EXIT_OK)
def main(argv): # Check SMF invocation environment if os.getenv("SMF_FMRI") == None or os.getenv("SMF_METHOD") != "start": sys.stderr.write("Command line invocation of %s unsupported.\n" \ % (sys.argv[0])) sys.stderr.write("This command is intended for smf(5) invocation only.\n") sys.exit(smf.SMF_EXIT_ERR_NOSMF) # Daemonise the service. create_daemon() # The user security attributes checked are the following: # Note that UID == 0 will match any profile search so # no need to check it explicitly. syslog.openlog("time-sliderd", 0, syslog.LOG_DAEMON) rbacp = RBACprofile() if rbacp.has_profile("ZFS File System Management"): gobject.threads_init() # Tell dbus to use the gobject mainloop for async ops dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) dbus.mainloop.glib.threads_init() # Register a bus name with the system dbus daemon systemBus = dbus.SystemBus() name = dbus.service.BusName("org.opensolaris.TimeSlider", systemBus) # Create and start the snapshot manger. Takes care of # auto snapshotting service and auto cleanup. snapshot = SnapshotManager(systemBus) snapshot.start() gobject.timeout_add(2000, monitor_threads, snapshot) mainloop = gobject.MainLoop() try: mainloop.run() except KeyboardInterrupt: mainloop.quit() sys.exit(smf.SMF_EXIT_OK) else: syslog.syslog(syslog.LOG_ERR, "%s has insufficient privileges to run time-sliderd!" \ % rbacp.name) syslog.closelog() sys.exit(smf.SMF_EXIT_ERR_PERM) syslog.closelog() sys.exit(smf.SMF_EXIT_OK)
def main(argv): parser = argparse.ArgumentParser() parser.add_argument('--foreground', action='store_true', help='Do not daemonize', default=False) parser.add_argument('--config', '-c', type=str, help='Configuration file', default='/etc/time-slider/timesliderd.conf') parser.add_argument('--configdump', action='store_true', help='Dump default values in config file format', default=False) args, _ = parser.parse_known_args() logger = logging.getLogger('time-slider') logger.setLevel(logging.DEBUG) if args.foreground: handler = logging.StreamHandler() handler.setFormatter(logging.Formatter('%(message)s')) else: handler = SysLogHandler(address='/dev/log') handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s', '%b %d %H:%M:%S time-sliderd:')) handler.setLevel(logging.DEBUG) logger.addHandler(handler) if args.configdump: timesliderconfig.configdump() sys.exit(smf.SMF_EXIT_OK) timesliderconfig.configfile = args.config # Daemonise the service. if not args.foreground: create_daemon() # The user security attributes checked are the following: # Note that UID == 0 will match any profile search so # no need to check it explicitly. rbacp = RBACprofile() if rbacp.has_profile("ZFS File System Management"): gobject.threads_init() # Tell dbus to use the gobject mainloop for async ops dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) dbus.mainloop.glib.threads_init() # Register a bus name with the system dbus daemon systemBus = dbus.SystemBus() name = dbus.service.BusName("org.opensolaris.TimeSlider", systemBus) # Create and start the snapshot manger. Takes care of # auto snapshotting service and auto cleanup. snapshot = SnapshotManager(systemBus) snapshot.start() gobject.timeout_add(2000, monitor_threads, snapshot) mainloop = gobject.MainLoop() try: mainloop.run() except KeyboardInterrupt: mainloop.quit() sys.exit(smf.SMF_EXIT_OK) else: logger.error( \ "%s has insufficient privileges to run time-sliderd!" \ % rbacp.name) sys.exit(smf.SMF_EXIT_ERR_PERM) sys.exit(smf.SMF_EXIT_OK)
def main(argv): parser = argparse.ArgumentParser() parser.add_argument('--foreground', action='store_true', help='Do not daemonize', default=False) parser.add_argument('--config', '-c', type=str, help='Configuration file', default='/etc/time-slider/timesliderd.conf') parser.add_argument('--configdump', action='store_true', help='Dump default values in config file format', default=False) args, _ = parser.parse_known_args() logger = logging.getLogger('time-slider') logger.setLevel(logging.DEBUG) if args.foreground: handler = logging.StreamHandler() handler.setFormatter(logging.Formatter('%(message)s')) else: handler = SysLogHandler(address='/dev/log') handler.setFormatter( logging.Formatter('%(asctime)s %(levelname)s: %(message)s', '%b %d %H:%M:%S time-sliderd:')) handler.setLevel(logging.DEBUG) logger.addHandler(handler) if args.configdump: timesliderconfig.configdump() sys.exit(smf.SMF_EXIT_OK) timesliderconfig.configfile = args.config # Daemonise the service. if not args.foreground: create_daemon() # The user security attributes checked are the following: # Note that UID == 0 will match any profile search so # no need to check it explicitly. rbacp = RBACprofile() if rbacp.has_profile("ZFS File System Management"): gobject.threads_init() # Tell dbus to use the gobject mainloop for async ops dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) dbus.mainloop.glib.threads_init() # Register a bus name with the system dbus daemon systemBus = dbus.SystemBus() name = dbus.service.BusName("org.opensolaris.TimeSlider", systemBus) # Create and start the snapshot manger. Takes care of # auto snapshotting service and auto cleanup. snapshot = SnapshotManager(systemBus) snapshot.start() gobject.timeout_add(2000, monitor_threads, snapshot) mainloop = gobject.MainLoop() try: mainloop.run() except KeyboardInterrupt: mainloop.quit() sys.exit(smf.SMF_EXIT_OK) else: logger.error( \ "%s has insufficient privileges to run time-sliderd!" \ % rbacp.name) sys.exit(smf.SMF_EXIT_ERR_PERM) sys.exit(smf.SMF_EXIT_OK)