我有一个python守护程序,希望将日志写入/ var / log / xxxxx / yyyy
该守护程序从start-stop-daemon启动,并为非特权用户提供chuid选项。
但是,当我启动程序时,它将崩溃,并在写入日志文件时出现权限错误。即使我将目录的权限设置为777,也会发生这种情况。
我已为非特权用户授予了适当的权限。我已经通过su向用户检查并在日志目录中写入了一个文件。这样就可以了。 此外,我检查了运行该程序的实际上是正确的用户。这也可以正确签出。 我还检查了start-stop-daemon是否存在问题,因此我从用户tm7手动启动了该程序。这带来了同样的问题。 最后,如果以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
--
答案 0 :(得分:0)
我会回答我自己的问题。
好读书是一种被低估的美德…… 它会尝试写入/ var / log / collector,而我的全部精力都放在了/ var / log / tm7 / collector。
希望您在这个无用的问题上不会浪费太多时间...