From a36df6973e051fcfda098fbdecf07d3382a5d877 Mon Sep 17 00:00:00 2001 From: bernis Date: Fri, 3 Mar 2017 16:51:19 +0100 Subject: [PATCH] add: script to restart run.py and pigpiod, example rc.local --- app/plot.py | 4 ++-- app/rfid.py | 9 +++++++-- rc.local.example | 18 ++++++++++++++++++ restart.sh | 10 ++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 rc.local.example create mode 100755 restart.sh diff --git a/app/plot.py b/app/plot.py index 0109e94..6a0f117 100644 --- a/app/plot.py +++ b/app/plot.py @@ -1,5 +1,5 @@ -import matplotlib #speed? -matplotlib.use('TkAgg') +import matplotlib +matplotlib.use('Agg') from matplotlib import pyplot as plt from matplotlib import units diff --git a/app/rfid.py b/app/rfid.py index 94c60f0..67417aa 100644 --- a/app/rfid.py +++ b/app/rfid.py @@ -7,7 +7,7 @@ except: import signal import thread import time - +#from multiprocessing import Process class RFID: @@ -17,7 +17,12 @@ class RFID: signal.signal(signal.SIGINT, self.stop) self.callback = callbackf self.loop = True - thread.start_new_thread(self.read, ()) + if 1: + thread.start_new_thread(self.read, ()) + else: + p = Process(target=self.read, args=()) + p.start() + p.join() def read(self): while True: diff --git a/rc.local.example b/rc.local.example new file mode 100644 index 0000000..6b076ce --- /dev/null +++ b/rc.local.example @@ -0,0 +1,18 @@ +sleep 1 +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib + +sleep 2 + +sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 5000 +echo "iptables nat started" + +sleep 2 +sudo pigpiod +echo "pigpiod started" + +sleep 2 +cd /home/pi/baroness && sudo ./restart.sh' & +echo "baroness started" + +exit 0 + diff --git a/restart.sh b/restart.sh new file mode 100755 index 0000000..004fffb --- /dev/null +++ b/restart.sh @@ -0,0 +1,10 @@ +#!/bin/bash +while true; do + su - pi -c 'cd /home/pi/baroness && FRAMEBUFFER=/dev/fb1 startx ./run.py' + now=$(date) + echo "Current time : $now" >> restart.log + killall pigpiod + sleep 5 + pigpiod + sleep 5 +done