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
It will show all logs inside terminal. I have following questions ::
- how can I create a log file, which will maintain all logs(inside /var/log/myapp/myapp.log).
- And I also want to categorize logs, like I just want to maintain failure logs only, so after created log file how to write a failure logs inside myapp.log. For now it shown all logs(both success failure) inside terminal.
- I am hitting golang api on port 8080, but whenever I checked port it doesn't seems busy. I didn't understand why port 8080 is not busy when I am running it as a service.Although it gives response in both cases but after stopping service and if running app in foreground it shows port 8080 is busy. Is there any reason for this?