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,7 +44,7 @@ def sigint_handler(signal, frame):
|
|||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
def main:
|
||||
client = mqtt.Client()
|
||||
client.on_connect = on_connect
|
||||
client.on_publish = on_publish
|
||||
|
|
@ -62,3 +63,8 @@ t.start()
|
|||
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