def main(): from optparse import OptionParser parser = OptionParser() parser.add_option("-d", "--directory", dest="directory", help="Uses DIRECTORY as working directory", metavar="DIRECTORY", default=os.path.expanduser('~/.housekeeper'), ) parser.add_option("-e", "--write-env-file", dest="write_envfile", help="Write environment file in working directory", action="store_true", default=False, ) parser.add_option("-r", "--replace", dest="replace", help="Replace running daemon if any", action="store_true", default=False, ) (options, args) = parser.parse_args() daemon = HousekeeperDaemon( directory=options.directory, write_envfile=options.write_envfile, replace=options.replace, ) daemon.main()
def handle_in(self, e): try: o = self.sock.recv_json() if len(o) is 0: return u = uevent.get(o) print 'get: %s' % u.event_obj u.publish() except: tb.print_exc() return class UEventDaemon(Daemon): def init(self): self.poller = mq.Poller() self.usvr = UEventSvr() self.poller.register(self.usvr) def _run(self): print 'ueventd(%s) is running...' % os.getpid() while True: self.poller.poll() if __name__ == "__main__": main(config.ueventd.pidfile, UEventDaemon)
'session': initr.active_session } self._pub.send_json(e) print e except: pass class EventDaemon(Daemon): def init(self): self.poller = mq.Poller() conn = gnsq.Nsqd(address=config.zoofs.ip, http_port=4151) pub = mq.pub_socket('eventd') self.ksub = KernelEventSub(pub) self.usub = UserspaceEventSub(pub) self.uevent = UEventSub(pub, conn) self.poller.register(self.ksub) self.poller.register(self.usub) self.poller.register(self.uevent) def _run(self): print 'NSQ_eventd(%s) is running...' % os.getpid() while True: self.poller.poll(config.nsq_eventd.poll_timeout_secs * 1000) self.uevent.elapse() if __name__ == "__main__": main(config.nsq_eventd.pidfile, EventDaemon)
#!/usr/bin/env python import sys from daemon import main if __name__ == '__main__': sys.exit(main())
'write_mb': w, 'timestamp': timestamp } self._samples.append(sample) def __iter__(self): return iter(self._samples) def __getitem__(self, idx): return self._samples.__getitem__(idx) def __getslice__(self, sidx, eidx): return self._samples.__getslice__(sidx, eidx) class SpeedioDaemon(Daemon): def init(self): self._poller = mq.Poller() self._rsp = Response() self._poller.register(self._rsp) def _run(self): print 'statd start...' while True: self._rsp.stat() self._poller.poll(2000) if __name__ == "__main__": main(config.speedd.pidfile, SpeedioDaemon)
log.info("diskled handle system ready") for raid in adm.Raid.all(): print raid.name, raid.health if raid.health == 'degraded': disks = [disk for disk in raid.raid_disks if disk.link and disk.online] if raid.rebuilding: self.ledctrl.blink(disks) else: self.ledctrl.blink_slow(disks) elif raid.health == 'failed': disks = [disk for disk in raid.raid_disks if disk.health <> 'failed' and disk.online] self.ledctrl.light_on(disks) except Exception as e: print e class DiskLEDDaemon(Daemon): def init(self): self.poller = mq.Poller() self.usub = UEventSub() self.poller.register(self.usub) def _run(self): print 'diskled(%s) is running...' % os.getpid() while True: self.poller.poll() if __name__ == "__main__": main(config.diskled.pidfile, DiskLEDDaemon)
} print gate self._samples.append(sample) def __iter__(self): return iter(self._samples) def __getitem__(self, idx): return self._samples.__getitem__(idx) def __getslice__(self, sidx, eidx): return self._samples.__getslice__(sidx, eidx) class SpeedioDaemon(Daemon): def init(self): self._poller = mq.Poller() conn = gnsq.Nsqd(address=config.zoofs.ip, http_port=config.zoofs.port) self._rsp = Response(conn) self._poller.register(self._rsp) def _run(self): print 'info(%s) is running...' % os.getpid() while True: self._rsp.stat() self._poller.poll(config.info.interval * 1000) if __name__ == "__main__": main(config.info.pidfile, SpeedioDaemon)
#this is for pyinstaller to ensure dependencies are met from twisted.web import server from twisted.web import wsgi from twisted.python.threadpool import ThreadPool from twisted.internet import reactor from options import get_executable_config import daemon if __name__ == "__main__": daemon.main(get_executable_config(), os.environ["_MEIPASS2"])
def gen_main(): from gen import main main()
req.close() def delete_sync_volume_task(name): req = mq.Request('syncd') try: req.request({'cmd': 'delete_sync_volume_task', 'name': name}, 10000) finally: req.close() def query_sync_progress(name): req = mq.Request('syncd') try: #import pdb #pdb.set_trace() rsp = req.request({'cmd': 'query_sync_progress', 'name': name}, 10000) if rsp and rsp['status'] == 'success': if rsp.has_key('detail'): return rsp['detail'] else: return None else: raise Exception() finally: req.close() if __name__ == '__main__': main(config.syncd.pidfile, SyncDaemon)
logging.info('Starting GTK loop.') Gtk.main() except: import traceback logging.error(traceback.format_exc()) def add_command_line_arguments_to(self, group): import os def mixer_list(argument): return argument.split(':') group.add_argument('--log-file', dest='log_file', metavar='FILE', default='/tmp/soundctld_'+str(os.getuid())+'.log') group.add_argument('--master', dest='master_mixer', metavar='MIXER', default='Master') group.add_argument('--outputs', dest='output_mixers', metavar='MIXERS', type=mixer_list, default='Speaker:Headphone', help='Colon-separated list of output mixers.') group.add_argument('--vol-steps', dest='num_volume_steps', metavar='N', type=int, default='25', help='Number of possible volume configurations, used' ' to define the volume increments and' ' decrements [default=25]') if __name__ == '__main__': daemon.main( SoundCtlDaemon('/tmp/soundctld.pid') )
else: db.connect() ret = api(**req['params']) db.close() rsp = json.dumps(ret) else: rsp = json.dumps(error.internal_error) self.sock.send(rsp) class Admd(Daemon): def init(self): guard = adm.Guard() self.khdl = KeventHandler(guard) apihdl = APIHandler(guard) self.poller = mq.Poller() self.poller.register(self.khdl) self.poller.register(apihdl) def _run(self): print 'admd(%s) is running...' % os.getpid() while True: self.poller.poll(config.admd.poll_timeout_secs * 1000) self.khdl.elapse() if __name__ == "__main__": main(config.admd.pidfile, Admd)
req = mq.Request('zerod') try: rsp = req.request({'cmd': 'query_zero_progress'}, 10000) if 'success' in rsp['status']: return rsp['detail'] else: raise Exception() finally: req.close() def test1(): d = ZeroDaemon('/tmp/z.pid') d.init() d.handle_zero_disks() d.handle_query_zero_progress() return d def test2(): disk = adm.Disk.lookup(dev_name='sdg') zp = ZeroProcess(disk) zp.prepare() zp.start() time.sleep(1) return zp if __name__ == '__main__': main(config.zerod.pidfile, ZeroDaemon)
def scan(): daemon.main("python portscanner.py") return redirect("/", code=302)
try: json_data = json.loads(data) if json_data['request_type'] == 'bcst_request': self._response_bcst(address) if json_data['request_type'] == 'ip_request': self._response_ip(address) except: log.info('message is not valid.') log.info('received %s byte from %s' % (len(data), address)) log.info(data) def _response_bcst(self, addr): message = copy.deepcopy(JSON_OK) message['uuid'] = self.uuid message['ifaces'] = self._getIfaces() self.server.sendto(json.dumps(message), addr) def _response_ip(self, addr): message = copy.deepcopy(JSON_OK) message['description'] = 'ip_addr' message['uuid'] = self.uuid message['ifaces'] = self._getIfaces() self.server.sendto(json.dumps(message), addr) def _getIfaces(self): return [info.ipaddr for info in network.ifaces().values() if info.link] if __name__ == '__main__': main(config.bcst.pidfile, BroadCast)
from env import config import json from load import * import logging import network import socket import commands import os from daemon import Daemon, main import time class NsqCD(Daemon): def _run(self): time.sleep(config.consumerd.interval) print 8888 if __name__ == "__main__": main(config.consumerd.pidfile, NsqCD)
def daemon_main(): from daemon import main main()
def bootstrap_main(): from bootstrap import main main()
try: req.request({'cmd': 'start_beep', 'mod': mod}, 10000) finally: req.close() def stop_beep(mod): req = mq.Request('beepd') try: req.request({'cmd': 'stop_beep', 'mod': mod}, 10000) finally: req.close() def test1(): bd = BeepDaemon('/tmp/p.pid') bd.init() bd.handle_start_beep('a') return bd def test2(): bp = BeepProcess() bp.start() time.sleep(1) return bp if __name__ == '__main__': main(config.beepd.pidfile, BeepDaemon)
from daemon import main main()
if authorize(): return handler() else: return unauthorized_error() def check_api_version(handler): ver = '1.0' m = re.search('/api/(\d+\.\d+)', web.ctx.path) if m: ver = m.group(1) web.ctx.path = re.sub('(/api)/\d+\.\d+', '\\1', web.ctx.path) if ver <> '1.0': raise web.notfound() return handler() class WebDaemon(Daemon): def _run(self): global app app.add_processor(check_api_version) app.add_processor(check_authorized) app.add_processor(db_connect) app = web.httpserver.StaticMiddleware(app.wsgifunc()) SocketIOServer(('0.0.0.0', 8081), app, resource="socket.io").serve_forever() if __name__ == "__main__": is_die = os.path.exists('/home/zonion/.llog') if not is_die: main(config.speedweb.pidfile, WebDaemon)
def main(): if len(argv) > 1: if argv[1] == '--version': print(''' gammacat (GNU coreutils) 1.0 Copyleft (C) 2019 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Torbjorn Granlund and Richard M. Stallman. ''') elif argv[1] in ['-d', '--daemon']: if os.path.isfile('daemon.txt'): print('\nA daemon is already running in the background') else: print('\nStarting daemon...') daemon.main() elif argv[1] in ['-s', '--server']: try: requests.post("http://localhost:5555", timeout=0.1) print('\nA server is already active') except requests.exceptions.ConnectionError: subprocess.call("server.bat") elif len(argv) == 2: if argv[1] in ['-c', '--connect']: print('\nusage: gammacat [-c, --connect] [HOST]') elif argv[1] in ['-e', '--search']: print('\nusage: gammacat [-e, --search] [HOST]') elif argv[1] in ['-cs', '--close-server']: try: r = requests.post("http://localhost:5555/shutdown", timeout=0.1) print(r.text) except requests.exceptions.ConnectionError: print('\nNo server is active on your computer right now') elif argv[1] in ['-cn', '--close-node']: try: r = requests.post("http://localhost:5550/shutdown", timeout=0.1) print(r.text) except requests.exceptions.ConnectionError: print('\nNo node is active on your computer right now ') else: print('\nusage: gammacat [OPTION] [HOST]') elif len(argv) == 3: if argv[1] in ['-c', '--connect']: try: requests.post("http://localhost:5550", timeout=0.1) print('\nA node is already active') except requests.exceptions.ConnectionError: subprocess.call(["node.bat", argv[2]]) elif argv[1] in ['-e', '--search']: try: requests.post("http://%s:5555" % argv[2], timeout=0.1) webbrowser.open_new_tab('http://%s:5555' % argv[2]) except requests.exceptions.ConnectionError: print('\nNo server is active on this host') else: print('\nusage: gammacat [OPTION] [HOST]') else: print('\nusage: gammacat [OPTION] [HOST]') else: print(''' usage: gammacat [OPTION] Software sollution for file search in a network of computers all connected to 1 main server. -s, --server open the gammacat web main server on your host -c, --connect connect to the server as a storage node -e, --search connect to the main server from the browser to search files -d, --daemon start a daemon that appends every file on your computer to a local database -cs, --close-server close the gammacat web main server that is open on your host -cn, --close-node close the storage node that is connected to the main server --version output version information and exits ''')
def main(args): """ Main entry point of the app """ cal_service = get_calendar_service() daemon.main(cal_service, args.id, args.rate)
proc = { 'pidfile': config[m].pidfile, 'file': config[m].file, 'daemon': m } proc['run'] = config[m].run if 'run' in config[ m] else 'python %s start' % proc['file'] proc['mtime'] = os.stat(proc['file']).st_mtime self.procs.append(proc) def _detect_file_change(self, proc): mtime = os.stat(proc['file']).st_mtime if proc['mtime'] <> mtime: print 'file change: %s' % proc['daemon'] proc['mtime'] = mtime with open(proc['pidfile'], 'r') as fin: pid = int(fin.read().strip()) os.kill(pid, signal.SIGTERM) def _run(self): time.sleep(config.spmd.detect_interval) for proc in self.procs: if config.spmd.detect_file_change: self._detect_file_change(proc) if not self._is_alive(proc): self._start_daemon(proc) if __name__ == "__main__": main(config.spmd.pidfile, SPMD)