So if I set the application to specifically log to /var/log/service-name/
logs do get written. Still unsure why, will update if I find out.
Logs not showing up when running JAR as a service
Pregunta
I have a fat JAR (Spring Boot) that if I start using java -jar filename.jar
creates two log files: one application log (that's usually stdout) and another one that creates an entry each time the webserver is hit.
Now when I start this as a service with a file in /etc/init.d/ (see snippet below) I don't get any log files created (other than /opt/service-name/log that only shows stdout before the application starts). It's not a permission issue - I tried starting the service with a user that doesn't have permissions and it doesn't start. And I tried find / logfile.log
with no luck.
daemon --user=root --pidfile=/var/run/service-name.pid java -jar /opt/service-name/filename.jar > /opt/service-name/log 2>&1 & echo $!
Any ideas why the log files are not being created?
Solución 2
Otros consejos
Try to first redirect stderr to stdout, and then redirect stdout to file, e.g.
daemon --user=root --pidfile=/var/run/service-name.pid java -jar /opt/service-name/filename.jar 2>&1 >/opt/service-name/log & echo $!
Also, the & echo $!
part looks suspicious to me. If I read specs correctly, a single &
may result in echo $!
returning before daemon has returned, which means you will get a wrong pid. Do you want to run && echo $!
or perhaps ; echo $!
instead?