1

I have created a systemd unit file like this:

[Unit]
Description=Menu Core Prices Update Daemon
After=network.target

[Service]
Environment="APP_CP=/opt/menu/menu-core-price-update"
Environment="JAVA_HOME=/usr/java/latest"
Environment="APP_NAME=menu-core-prices-update-0.0.1-SNAPSHOT.jar"
Environment="LOGPATH=/var/log/menu/menu-core-price-update"
ExecStartPre=/bin/mkdir -pm 0755 ${LOGPATH}
ExecStart=/bin/bash -c "$JAVA_HOME/bin/java -jar ${APP_NAME}"
PIDFile=/run/menu/menu-core-price-update%i.pid
Restart=on-abort
RuntimeDirectory=menu-core-price-update
RuntimeDirectoryMode=755
WorkingDirectory=/opt/menu/menu-core-price-update

[Install]
WantedBy=multi-user.target

but when I enable the service, I got this error:

 systemctl status menu-core-prices-update.service
    ● menu-core-prices-update.service - menu Core Prices Update Daemon
       Loaded: loaded (/usr/lib/systemd/system/menu-core-prices-update.service; enabled; vendor preset: enabled)
       Active: failed (Result: exit-code) since Sat 2018-07-21 06:17:43 UTC; 6min ago
      Process: 5154 ExecStartPre=/bin/mkdir -pm 0755 ${LOGPATH} (code=exited, status=200/CHDIR)

and there is no log in /var/log/

1 Answer 1

1

You're misunderstanding the purpose of this line in the unit file:

Environment="LOGPATH=/var/log/menu/menu-core-price-update"

This property is to setup a directory location for your Java application to log to if it so chooses. But if the application generates no logs via log4j or whatever logger it uses, there will be no logs in this location.

With systemd services all the logging for your application service is done through journald. To view your applications logs:

$ journalctl -u menu-core-price-update.service

Example

Here's the first 10 lines of my sshd's logs

$ journalctl -u sshd.service -n 10
-- Logs begin at Tue 2018-07-17 16:01:01 EDT, end at Sat 2018-07-21 03:05:37 EDT. --
Jul 21 00:55:04 centos7 sshd[9059]: Connection closed by 127.0.0.1 port 33718 [preauth]
Jul 21 00:55:04 centos7 sshd[9067]: Connection closed by 127.0.0.1 port 33720 [preauth]
Jul 21 00:55:08 centos7 sshd[9078]: pam_unix(sshd:auth): authentication failure; logname= uid=
Jul 21 00:55:10 centos7 sshd[9078]: Failed password for user1 from 127.0.0.1 port 33722 ssh2
Jul 21 00:55:10 centos7 sshd[9078]: error: maximum authentication attempts exceeded for user1
Jul 21 00:55:10 centos7 sshd[9078]: Disconnecting: Too many authentication failures [preauth]
Jul 21 00:55:21 centos7 sshd[9110]: Connection closed by 127.0.0.1 port 33724 [preauth]
Jul 21 00:55:21 centos7 sshd[9118]: Connection closed by 127.0.0.1 port 33726 [preauth]
Jul 21 00:55:23 centos7 sshd[9129]: Accepted password for user1 from 127.0.0.1 port 33728 ssh2
Jul 21 02:24:41 centos7 sshd[9433]: Accepted publickey for vagrant from 10.0.2.2 port 50662 ss

References

1
  • 1
    Hint: You are currently not seeing messages from other users and the system. Users in the 'systemd-journal' group can see all messages. Pass -q to turn off this notice. No journal files were opened due to insufficient permissions.
    – en Peris
    Jul 21, 2018 at 7:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .