From 737319dfb1360f62982076b54f1b0a16188a4f83 Mon Sep 17 00:00:00 2001 From: Mark McIntyre Date: Wed, 25 Aug 2021 18:36:58 +0100 Subject: [PATCH 1/4] gracefully handle missing keyfile --- sendToLive.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) 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') From e3db37a61062c35a6087ec96cdb065dd428cb8b8 Mon Sep 17 00:00:00 2001 From: Mark McIntyre Date: Wed, 25 Aug 2021 18:37:17 +0100 Subject: [PATCH 2/4] add manual restart capability --- restartLiveMon.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/restartLiveMon.sh b/restartLiveMon.sh index e6f62a5..b8466e9 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 1 ] +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 -fn | grep liveMon | grep -v grep | awk '{print $1}') + 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 From 5ba08110100e571a67711d14f74c8085baa3362e Mon Sep 17 00:00:00 2001 From: Mark McIntyre Date: Wed, 25 Aug 2021 18:40:23 +0100 Subject: [PATCH 3/4] bugfix --- restartLiveMon.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restartLiveMon.sh b/restartLiveMon.sh index b8466e9..801a662 100755 --- a/restartLiveMon.sh +++ b/restartLiveMon.sh @@ -5,7 +5,7 @@ # just add this to your crontab: # */10 * * * * /home/pi/source/ukmon-pitools/restartLiveMon.sh >/dev/null 2>&1 force=0 -if [ $# -gt 1 ] +if [ $# -gt 0 ] then force=1 fi From df9b367f42bdbd20a5dbc222533251382850e195 Mon Sep 17 00:00:00 2001 From: Mark McIntyre Date: Wed, 25 Aug 2021 18:43:29 +0100 Subject: [PATCH 4/4] bugfix --- restartLiveMon.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restartLiveMon.sh b/restartLiveMon.sh index 801a662..843e16e 100755 --- a/restartLiveMon.sh +++ b/restartLiveMon.sh @@ -12,7 +12,7 @@ fi x=$(ps -ef | grep liveMon |wc -l) if [[ $x -lt 2 || $force -eq 1 ]] then - pids=$(ps -fn | grep liveMon | grep -v grep | awk '{print $1}') + pids=$(ps -ef | grep liveMon | grep -v grep | awk '{print $2}') if [ "$pids" != "" ] then kill -9 $pids