简体   繁体   中英

Permission error on logdirectory in Ubuntu 18.10

I have a python daemon program that wants to write logs to /var/log/xxxxx/yyyy

The daemon is started with start-stop-daemon with the option chuid to the unprivileged user.

However when I start the program it will crash with a Permission error on the write to the logfile. This will happen even if I set the permissions of the directories to 777.

I have given the proper permissions for the unprivileged user. I have checked this by su to the user and writing a file in the log directory. This works OK. Furthermore I have checked that it is actually the proper user that is running the program. This also checks out correctly. Also I checked if it was a problem with start-stop-daemon, so I started the program manually from the user tm7. This gives the same problem. Finally the program will run if started as root.

Jan 03 08:56:09 testlinux testde[13205]:  * Starting DataExtractor tm7 carp suite
Jan 03 08:56:09 testlinux systemd-resolved[574]: Server returned error NXDOMAIN, mitigating potential DNS violation DVE-2018-0001, retrying transaction with reduced feature level UDP.
Jan 03 08:56:09 testlinux testde[13205]: sourcedir /opt/tm7/dataextractor/src
Jan 03 08:56:09 testlinux testde[13205]: sys.path is ['/opt/tm7/dataextractor/src', '/opt/tm7/dataextractor', '/opt/tm7/dataextractor/src', '/opt/tm7/venv/dataextractor/lib/python36.zip', '/opt/tm7/
Jan 03 08:56:09 testlinux testde[13205]: Collector started with config /etc/tm7/Customers/Sparq/config.yml
Jan 03 08:56:09 testlinux testde[13205]: Config setup started with customer Sparq and file None
Jan 03 08:56:09 testlinux testde[13205]: get definition directory
Jan 03 08:56:09 testlinux testde[13205]: Definition directory: /etc/tm7/Customers
Jan 03 08:56:09 testlinux testde[13205]: ******* tm7 Start dataextractor_main version developer Logging in /var/log/collector using /etc/tm7/Customers/generic/logger.ini
Jan 03 08:56:09 testlinux testde[13205]: Traceback (most recent call last):
Jan 03 08:56:09 testlinux testde[13205]:   File "src/main.py", line 72, in <module>
Jan 03 08:56:09 testlinux testde[13205]:     main()
Jan 03 08:56:09 testlinux testde[13205]:   File "src/main.py", line 64, in main
Jan 03 08:56:09 testlinux testde[13205]:     setup_loggers('main')
Jan 03 08:56:09 testlinux testde[13205]:   File "/opt/tm7/dataextractor/src/utils/SetUpLog.py", line 94, in setup_loggers
Jan 03 08:56:09 testlinux testde[13205]:     fileConfig(logconf, defaults=None, disable_existing_loggers=False)
Jan 03 08:56:09 testlinux testde[13205]:   File "/usr/lib/python3.6/logging/config.py", line 84, in fileConfig
Jan 03 08:56:09 testlinux testde[13205]:     handlers = _install_handlers(cp, formatters)
Jan 03 08:56:09 testlinux testde[13205]:   File "/usr/lib/python3.6/logging/config.py", line 148, in _install_handlers
Jan 03 08:56:09 testlinux testde[13205]:     h = klass(*args)
Jan 03 08:56:09 testlinux testde[13205]:   File "/usr/lib/python3.6/logging/handlers.py", line 150, in __init__
Jan 03 08:56:09 testlinux testde[13205]:     BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
Jan 03 08:56:09 testlinux testde[13205]:   File "/usr/lib/python3.6/logging/handlers.py", line 57, in __init__
Jan 03 08:56:09 testlinux testde[13205]:     logging.FileHandler.__init__(self, filename, mode, encoding, delay)
Jan 03 08:56:09 testlinux testde[13205]:   File "/usr/lib/python3.6/logging/__init__.py", line 1032, in __init__
Jan 03 08:56:09 testlinux testde[13205]:     StreamHandler.__init__(self, self._open())
Jan 03 08:56:09 testlinux testde[13205]:   File "/usr/lib/python3.6/logging/__init__.py", line 1061, in _open
Jan 03 08:56:09 testlinux testde[13205]:     return open(self.baseFilename, self.mode, encoding=self.encoding)
Jan 03 08:56:09 testlinux testde[13205]: PermissionError: [Errno 13] Permission denied: '/var/log/collector/collector-main.log'
Jan 03 08:56:09 testlinux systemd[1]: testde.service: Control process exited, code=exited status=1
Jan 03 08:56:09 testlinux systemd[1]: testde.service: Failed with result 'exit-code'.
Jan 03 08:56:09 testlinux systemd[1]: Failed to start LSB: DataExtractor.
-- Subject: Unit testde.service has failed
-- Defined-By: systemd
--

I 'll answer my own question.

Reading well is an underestimated virtue...... It tries to write to /var/log/collector, while all my effort has been directed to /var/log/ tm7 /collector.

Hope you didn't waste too much time on this useless question......

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM