This seems like it should be simple, but I am struggling to make it work. I am trying to set up a systemd service so output from a logging program (varnishncsa) that outputs log entries from memory can be piped to cronolog. The only way I have been able to make it work is in the foreground. I am trying to make it work as a systemd service. The script that takes over the foreground is:
#!/bin/bash
/usr/bin/varnishncsa -F '%{X-Real-IP}i %l %u %t "%r" %s %b "%{Referer}i" "%{User-agent}i"' -q "ReqHeader:Host ~ '(^|\.)example\.com$'" -C |/usr/sbin/cronolog "/example/varnish_access_log.%Y-%m-%d"
The systemd service setup I am trying is:
[Unit]
Description=Example website Varnish Cache HTTP accelerator NCSA logging daemon
After=varnish.service
[Service]
RuntimeDirectory=varnishncsa
Type=forking
PIDFile=/run/varnishncsa/varnishncsa-example.pid
User=varnish
Group=varnish
ExecStart=/usr/local/bin/varnishncsa-example.sh
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
Which is based on the provided systemd service for running as a daemon and writing to a file (I can't run it directly as a daemon, using -D and -P, and pipe the output):
[Unit]
Description=Varnish Cache HTTP accelerator NCSA logging daemon
After=varnish.service
[Service]
RuntimeDirectory=varnishncsa
Type=forking
PIDFile=/run/varnishncsa/varnishncsa.pid
User=varnish
Group=varnish
ExecStart=/usr/bin/varnishncsa -a -w /var/log/varnish/varnishncsa.log -D -P /run/varnishncsa/varnishncsa.pid
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
I have tried many options to make it run in the background, but can't get anything to work, and can't find anything online that deals with this situation specifically. Probably because systemd is still quite new, or others doing this have more idea what they are doing!
Any help greatly appreciated.
Asked by user194553
Apr 7, 2017, 06:27 PM
Last activity: Apr 7, 2017, 07:12 PM
Last activity: Apr 7, 2017, 07:12 PM