systemd
サービスの出力をファイルにリダイレクトしようとしていますが、うまくいかないようです:
[Unit]
Description=customprocess
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/binary1 agent -config-dir /etc/sample.d/server
StandardOutput=/var/log1.log
StandardError=/var/log2.log
Restart=always
[Install]
WantedBy=multi-user.target
私のアプローチを修正してください。
ベストアンサー1
この問題を解決するには、もっとエレガントな方法があると思います。stdout/stderr を識別子とともに syslog に送信し、syslog マネージャーに出力をプログラム名で分割するように指示します。
systemd サービス ユニット ファイルで次のプロパティを使用します。
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=<your program identifier> # without any quote
/etc/rsyslog.d/<new_file>.conf
次に、ディストリビューションが rsyslog を使用して syslog を管理していると仮定して、次の内容のファイルを作成します。
if $programname == '<your program identifier>' then /path/to/log/file.log
& stop
次に、ログ ファイルを syslog で書き込み可能にします。
# ls -alth /var/log/syslog
-rw-r----- 1 syslog adm 439K Mar 5 19:35 /var/log/syslog
# chown syslog:adm /path/to/log/file.log
rsyslog ( sudo systemctl restart rsyslog
) を再起動してお楽しみください。プログラムの stdout/stderr は journalctl ( ) を通じて引き続き利用できますsudo journalctl -u <your program identifier>
が、選択したファイルでも利用できるようになります。