0

我在 systemd 服务下面写了一个教程,该服务在 gunicorn 上运行烧瓶应用程序。我可以看到访问日志,/var/log/nginx/但看不到 python 烧瓶应用程序中发生的错误日志!如何将错误记录到 systemd 服务的磁盘?

$ cat /etc/systemd/system/gunicorn.service                                          [Unit]
Description=gunicorn daemon for /var/www/html/start_backend.py
After=network.target

[Service]
PermissionsStartOnly = true
User=ciasto
Group=www-data
RuntimeDirectory=gunicorn
WorkingDirectory=/var/www/html/
ExecStartPre = /bin/chown -R pi:www-data /var/www/html/
Environment="APP_SETTINGS=production"
Environment="DB_USER=username"
Environment="DB_PWD=password"
Environment="DB_HOST="ceres.local"
ExecStart=/usr/bin/env gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 start_backend:web_app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

为了获得异常错误日志,我在下面添加了两行:

StandardOutput=file:/var/log/gunicorn/log1.log
StandardError=file:/var/log/gunicorn/log2.log

我重新启动了 gunicorn 服务而不是访问 URL 以引发异常错误,检查我期望日志到达的路径。但我什么也没看到

sudo systemctl status  gunicorn                                 ● gunicorn.service - gunicorn daemon for /var/www/html/start_backend.py
   Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-01-03 22:42:31 IST; 1min 9s ago
  Process: 3944 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
  Process: 3947 ExecStartPre=/bin/chown -R ciasto:www-data /var/www/html/ (code=exited, status=0/SU Main PID: 3950 (gunicorn)
   CGroup: /system.slice/gunicorn.service
           ├─3950 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4            ├─3965 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4            ├─3966 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4            ├─3967 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4            └─3968 /usr/bin/python /usr/bin/gunicorn --bind=unix:/tmp/gunicorn.sock --workers=4 
Jan 03 22:43:34 ceres env[3950]:     db.connect()
Jan 03 22:43:34 ceres env[3950]:   File "/home/ciasto/.local/lib/python2.7/site-packages/peewee.py"Jan 03 22:43:34 ceres env[3950]:     self._state.set_connection(self._connect())
Jan 03 22:43:34 ceres env[3950]:   File "/home/ciasto/.local/lib/python2.7/site-packages/peewee.py"Jan 03 22:43:34 ceres env[3950]:     return mysql.connect(db=self.database, **self.connect_paraJan 03 22:43:34 ceres env[3950]:   File "/home/ciasto/.local/lib/python2.7/site-packages/MySQLdb/__Jan 03 22:43:34 ceres env[3950]:     return Connection(*args, **kwargs)
Jan 03 22:43:34 ceres env[3950]:   File "/home/ciasto/.local/lib/python2.7/site-packages/MySQLdb/coJan 03 22:43:34 ceres env[3950]:     super(Connection, self).__init__(*args, **kwargs2)
Jan 03 22:43:34 ceres env[3950]: TypeError: connect() argument 1 must be string, not None
ciasto@ceres:/etc/systemd/system $ cd /var/log/gunicorn                                            ciasto@ceres:/var/log/gunicorn $ ll
total 0
ciasto@ceres:/var/log/gunicorn $
4

0 回答 0