diff --git a/restartLiveMon.sh b/restartLiveMon.sh index e6f62a5..843e16e 100755 --- a/restartLiveMon.sh +++ b/restartLiveMon.sh @@ -4,8 +4,19 @@ # if it is killed. # just add this to your crontab: # */10 * * * * /home/pi/source/ukmon-pitools/restartLiveMon.sh >/dev/null 2>&1 +force=0 +if [ $# -gt 0 ] +then + force=1 +fi x=$(ps -ef | grep liveMon |wc -l) -if [ $x -lt 2 ] +if [[ $x -lt 2 || $force -eq 1 ]] then + pids=$(ps -ef | grep liveMon | grep -v grep | awk '{print $2}') + if [ "$pids" != "" ] + then + kill -9 $pids + fi + echo "restarting liveMonitor" /home/pi/source/ukmon-pitools/liveMonitor.sh >> /home/pi/RMS_data/logs/ukmon-live.log 2>&1 & fi \ No newline at end of file diff --git a/sendToLive.py b/sendToLive.py index ab2547e..e3ec87e 100644 --- a/sendToLive.py +++ b/sendToLive.py @@ -101,18 +101,22 @@ def singleUpload(cap_dir, dir_file): exit(1) # get credentials - with open(os.path.join(myloc, 'live.key'), 'r') as inif: - lines = inif.readlines() - for li in lines: - if 'AWS_ACCESS_KEY_ID' in li: - awskey = li.split('=')[1].strip() - if 'AWS_SECRET_ACCESS_KEY' in li: - awssec = li.split('=')[1].strip() - if 'AWS_DEFAULT_REGION' in li: - awsreg = li.split('=')[1].strip() - if awssec is None or awskey is None or awsreg is None: + try: + with open(os.path.join(myloc, 'live.key'), 'r') as inif: + lines = inif.readlines() + for li in lines: + if 'AWS_ACCESS_KEY_ID' in li: + awskey = li.split('=')[1].strip() + if 'AWS_SECRET_ACCESS_KEY' in li: + awssec = li.split('=')[1].strip() + if 'AWS_DEFAULT_REGION' in li: + awsreg = li.split('=')[1].strip() + except Exception: print('unable to locate AWS credentials, aborting') exit(1) + if awssec is None or awskey is None or awsreg is None: + print('credentials file malformed, aborting') + exit(1) conn = boto3.Session(aws_access_key_id=awskey, aws_secret_access_key=awssec, region_name=awsreg) s3 = conn.resource('s3')