Daemonize mqtt sender python script
This commit is contained in:
parent
165e59e1a1
commit
f0fc433954
1 changed files with 18 additions and 12 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import paho.mqtt.client as mqtt
|
||||
import ssl
|
||||
from threading import Thread
|
||||
from daemonize import Daemonize
|
||||
import redis
|
||||
import time
|
||||
import signal
|
||||
|
|
@ -43,22 +44,27 @@ def sigint_handler(signal, frame):
|
|||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
client = mqtt.Client()
|
||||
client.on_connect = on_connect
|
||||
client.on_publish = on_publish
|
||||
def main:
|
||||
client = mqtt.Client()
|
||||
client.on_connect = on_connect
|
||||
client.on_publish = on_publish
|
||||
|
||||
|
||||
|
||||
client.tls_set(
|
||||
"/etc/letsencrypt/live/resqaws.jankstudio.com/fullchain.pem", cert_reqs=ssl.CERT_NONE,
|
||||
tls_version=ssl.PROTOCOL_TLSv1)
|
||||
client.tls_set(
|
||||
"/etc/letsencrypt/live/resqaws.jankstudio.com/fullchain.pem", cert_reqs=ssl.CERT_NONE,
|
||||
tls_version=ssl.PROTOCOL_TLSv1)
|
||||
|
||||
client.connect("resqaws.jankstudio.com", 8883, 60)
|
||||
t = Thread(target=getRedis, args=(1,))
|
||||
client.connect("resqaws.jankstudio.com", 8883, 60)
|
||||
t = Thread(target=getRedis, args=(1,))
|
||||
|
||||
t.start()
|
||||
t.start()
|
||||
|
||||
signal.signal(signal.SIGINT, sigint_handler)
|
||||
client.loop_forever()
|
||||
signal.signal(signal.SIGINT, sigint_handler)
|
||||
client.loop_forever()
|
||||
|
||||
|
||||
|
||||
pid = "/tmp/mqtt_sender.pid"
|
||||
daemon = Daemonize(app="mqtt_sender", pid=pid, action=main)
|
||||
daemon.start()
|
||||
|
|
|
|||
Loading…
Reference in a new issue