added kill and restart args to stop or restart the daemon if running...
This commit is contained in:
parent
8dd81c5eee
commit
eba54b8cb0
3 changed files with 25 additions and 13 deletions
28
uplink
28
uplink
|
|
@ -56,7 +56,13 @@ def parse_args():
|
|||
help="cron mode executes the script only once without loop (default: false)")
|
||||
|
||||
mode.add_argument("-d", "--daemon", default=False, dest="daemon", action="store_true",
|
||||
help="run as native daemon (default: false)")
|
||||
help="run as native daemon (default: false)")
|
||||
|
||||
parser.add_argument("-k", "--kill", default=False, dest="kill", action="store_true",
|
||||
help="kill the daemon if it is running (default: false)")
|
||||
|
||||
parser.add_argument("-r", "--restart", default=False, dest="restart", action="store_true",
|
||||
help="restart the daemon if it is running(default: false)")
|
||||
|
||||
mode.add_argument("-f", "--foreground", default=False, dest="foreground", action="store_true",
|
||||
help="run looped in foreground (default: false)")
|
||||
|
|
@ -66,12 +72,14 @@ def parse_args():
|
|||
"(default: 60)")
|
||||
|
||||
"""
|
||||
TODO: maybe make database connection information as args... not sure.
|
||||
parser.add_argument("-b", "--database", metavar="DATABASE", help="database to use")
|
||||
|
||||
parser.add_argument("-u", "--user", type=str, help="database username")
|
||||
|
||||
parser.add_argument("-p", "--password", type=str, help="database password")
|
||||
"""
|
||||
|
||||
parser.add_argument("-l", "--logfile", metavar="LOGFILE", help="logfile to use")
|
||||
|
||||
parser.add_argument("-n", "--logcount", default=5, type=int,
|
||||
|
|
@ -132,7 +140,7 @@ def main():
|
|||
config_data = configfile.read()
|
||||
config = json.loads(config_data)
|
||||
except Exception as err:
|
||||
logger.error(str("uplink: configuration error! " + str(err)))
|
||||
logger.error(str("uplink: configuration error!\n" + str(err)))
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
|
|
@ -145,24 +153,30 @@ def main():
|
|||
# interval set in args is overriding configuration and default
|
||||
config["interval"] = args.interval
|
||||
|
||||
uplink = Uplink("/tmp/uplink.pid", config)
|
||||
pid_file = "/tmp/uplink.pid"
|
||||
u = Uplink(pid_file, config)
|
||||
|
||||
if args.cron:
|
||||
from threading import Thread
|
||||
for i in range(len(config["uplinks"])):
|
||||
t = Thread(target=uplink.fetch_data, args=(config, i))
|
||||
t = Thread(target=u.fetch_data, args=(config, i))
|
||||
t.start()
|
||||
elif args.daemon:
|
||||
uplink.start()
|
||||
if args.kill:
|
||||
u.stop()
|
||||
elif args.restart:
|
||||
u.restart()
|
||||
else:
|
||||
u.start()
|
||||
elif args.foreground:
|
||||
from threading import Thread
|
||||
while True:
|
||||
for i in range(len(config["uplinks"])):
|
||||
t = Thread(target=uplink.fetch_data, args=(config, i))
|
||||
t = Thread(target=u.fetch_data, args=(config, i))
|
||||
t.start()
|
||||
try:
|
||||
time.sleep(config["interval"])
|
||||
except KeyboardInterrupt:
|
||||
except KeyboardInterrupt as err:
|
||||
logger.info(str("uplink: program terminated by user!"))
|
||||
sys.exit(0)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue