Flag system tasks that fail

This commit is contained in:
James Barnsley
2019-04-04 14:37:40 +13:00
parent b8818e528e
commit 0a6dd7bf23
3 changed files with 16 additions and 15 deletions

View File

@ -19,7 +19,7 @@ class IrisSystemThread(Thread):
logger.info("Running system action: "+self.action)
try:
self.check_system_access()
self.can_run()
except Exception, e:
logger.error(e)
@ -30,10 +30,10 @@ class IrisSystemThread(Thread):
if self.callback:
self.callback(False, error)
return
# Run the actual task (this is the process-blocking instruction)
output = subprocess.check_output(["sudo "+self.path+"/system.sh "+self.action], shell=True)
output = subprocess.check_output(["sudo -n "+self.path+"/system.sh "+self.action], shell=True)
# And then, when complete, return to our callback
if self.callback:
@ -48,15 +48,13 @@ class IrisSystemThread(Thread):
#
# @return boolean or exception
##
def check_system_access(self, *args, **kwargs):
def can_run(self, *args, **kwargs):
# Attempt an empty call to our system file
process = subprocess.Popen("sudo -n "+self.path+"/system.sh", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
result, error = process.communicate()
exitCode = process.wait()
# Some kind of failure, so we can't run any commands this way
if exitCode > 0:
raise Exception("Password-less access to "+self.path+"/system.sh was refused. Check your /etc/sudoers file.")
else:
# If this fails, we can't run any commands this way
try:
subprocess.check_output("sudo -n "+self.path+"/system.sh", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
return True
except Exception, e:
raise Exception("Password-less access to "+self.path+"/system.sh was refused. Check your /etc/sudoers file.")
return False

View File

@ -17,10 +17,13 @@ elif [[ $1 = "local_scan" ]]; then
elif [[ $1 = "test" ]]; then
sleep 10
sleep 3
TEST="$(echo 'Hello, this is your bash speaking. I was sleeping for 10 seconds.')"
TEST="$(echo 'Hello, this is your bash speaking. I was sleeping for 3 seconds.')"
echo -e "${TEST}"
else;
echo -e "Unsupported system task"
fi
exit 0

View File

@ -157,7 +157,7 @@ const PusherMiddleware = (function(){
break;
case 'test_error':
store.dispatch(uiActions.processFinished('test'));
store.dispatch(uiActions.createNotification({type: 'bad', content: 'Test failed'}));
store.dispatch(uiActions.createNotification({type: 'bad', content: message.params.message, description: message.params.description}));
break;
}