2

I am running Go binary as a service on ubuntu 16.04,and not able to create log file which is owned by syslog. I have created a services for myapp.service and it looks like as follows:

[Unit]
Description=myapp

[Service]
Type=simple
Restart=always
RestartSec=30
WorkingDirectory= /home/go/src/myapp
ExecStart=/home/go/src/myapp/myapp  

# myapp.log owned by syslog
PermissionsStartOnly=true
ExecStartPre=/bin/mkdir -p /var/log/myapp
ExecStartPre=/bin/chown syslog:adm /var/log/myapp
ExecStartPre=/bin/chmod 755 /var/log/myapp
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=myapp                           

[Install]
WantedBy=multi-user.target

Now It just creates a folder inside /var/log/myapp . But didn't creates any myapp.log file inside myapp folder. I can check these logs using command ::

sudo journalctl -f -u myapp

After this using rsyslog to manage syslogs, created a file inside /etc/rsyslog.d/myapp.conf with the following content:

if $programname == 'myapp' then /var/log/myapp/myapp.log
& stop

After this I restarted service.It creates a log file for me. But this includes log for both success and failure, and I just want to create failure logs, how is this possible??

0

You must log in to answer this question.

Browse other questions tagged .