Skip to content

Commit

Permalink
now with permission fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
witlox committed Jun 19, 2019
1 parent 42ae138 commit bcdd80f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions dcron/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def main():
if args.cron == 'memory':
processor = Processor(args.udp_communication_port, storage, cron=CronTab(tab="""* * * * * command"""))
elif args.cron_user:
processor = Processor(args.udp_communication_port, storage, cron=CronTab(tabfile=args.cron, user=args.cron_user))
processor = Processor(args.udp_communication_port, storage, cron=CronTab(tabfile=args.cron, user=args.cron_user), user=args.cron_user)
else:
processor = Processor(args.udp_communication_port, storage, cron=CronTab(tabfile=args.cron, user=False))
processor = Processor(args.udp_communication_port, storage, cron=CronTab(tabfile=args.cron, user=False), user='root')
else:
processor = Processor(args.udp_communication_port, storage)

Expand Down
4 changes: 3 additions & 1 deletion dcron/cron/cronitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ def log(self):
if data and (not self.user or data['user'] == self.user):
result.append(data)
except FileNotFoundError:
pass
self.logger.error("could not find syslog file for retrieving logs for {0}".format(self.command))
except PermissionError:
self.logger.error("could not access syslog file for retrieving logs for {0}".format(self.command))
return result

@property
Expand Down
5 changes: 4 additions & 1 deletion dcron/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Processor(object):

logger = logging.getLogger(__name__)

def __init__(self, udp_port, storage, cron=None):
def __init__(self, udp_port, storage, cron=None, user=None):
self.queue = asyncio.Queue()
self._buffer = []
self.udp_port = udp_port
Expand All @@ -51,6 +51,7 @@ def __init__(self, udp_port, storage, cron=None):
self.cron = CronTab(tabfile='/etc/crontab', user=False)
else:
self.cron = cron
self.user = user

def update_status(self, status_message):
self.logger.debug("got full status message in buffer ({0}".format(status_message))
Expand Down Expand Up @@ -85,6 +86,8 @@ def add_job(self, new_job):
self.logger.info("job already defined in tab, skipping it")
else:
self.logger.info("adding job {0} to cron {1}".format(new_job, self.cron.filename))
if self.user:
new_job.user = self.user
self.cron.append(new_job)
self.cron.write()
else:
Expand Down

0 comments on commit bcdd80f

Please sign in to comment.