Systemd 服务未记录

Systemd 服务未记录

我有一个 systemd 服务。尽管我尽了最大努力,但还是没有出现任何日志。这是服务文件:

[Unit]
Description=Load Balancer

[Service]
WorkingDirectory=/home/lb
ExecStart=/usr/lib/jvm/jdk-20/bin/java --enable-preview -jar /home/lb/app.jar
User=lb
Type=simple
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

我也尝试添加

StandardOutput=journal
StandardError=journal

它什么也没做。中也没有消息/var/log/messages。磁盘未满:

# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            5.9G     0  5.9G   0% /dev
tmpfs           1.2G  624K  1.2G   1% /run
/dev/sda3       293G  3.3G  275G   2% /
tmpfs           5.9G     0  5.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
/dev/sda2       2.0G   84M  1.8G   5% /boot
tmpfs           1.2G     0  1.2G   0% /run/user/997

journactl 没有显示任何内容:

# journalctl --user -u lb
No journal files were found.
-- No entries --

# journalctl -u lb
-- Journal begins at Sat 2023-05-13 12:59:37 CEST, ends at Sat 2023-05-13 13:46:23 CEST. --
May 13 12:59:59 myserver systemd[1]: lb.service: Main process exited, code=exited, status=143/n/a
May 13 12:59:59 myserver systemd[1]: lb.service: Failed with result 'exit-code'.
May 13 12:59:59 myserver systemd[1]: lb.service: Consumed 3.067s CPU time.

我看到的只有这些失败消息。它们在我重新启动服务时发生。

为了安全起见,我重写了代码,除了打印一些日志外不执行任何操作:

# /usr/lib/jvm/jdk-20/bin/java -jar app.jar
[LoadBalancer] [2023-05-13 13:51:22] [INFO] Hello, world!
[LoadBalancer] [2023-05-13 13:51:22] [ERROR] Second message is an error

我已经运行systemctl daemon-reload多次了。东西正在运行:

# ps auxf
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.0 167072 11868 ?        Ss    2022  67:48 /lib/systemd/systemd --system --deserialize 22
root     3286623  0.0  0.0 220800  5252 ?        Ssl  Mar26   7:56 /usr/sbin/rsyslogd -n -iNONE
systemd+ 2751434  0.0  0.0  88440  6168 ?        Ssl  Apr30   0:04 /lib/systemd/systemd-timesyncd
root     2751463  0.0  0.0  21188  4824 ?        Ss   Apr30   0:02 /lib/systemd/systemd-udevd
root     2814177  0.0  0.0  48316  9240 ?        Ss   12:57   0:00 /lib/systemd/systemd-journald

我需要查看我的日志。谢谢您的帮助。

编辑:完整输出service lb status(使用真实代码而不是日志记录语句。真实代码打印已启动消息):

# service lb status
● lb.service - Load Balancer
     Loaded: loaded (/etc/systemd/system/lb.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2023-05-13 17:13:03 CEST; 4s ago
   Main PID: 19711 (java)
      Tasks: 34 (limit: 14334)
     Memory: 75.2M
        CPU: 2.907s
     CGroup: /system.slice/lb.service
             └─19711 /usr/lib/jvm/jdk-20/bin/java --enable-preview -jar /home/lb/app.jar

答案1

我放弃了修复它。重新安装了整个服务器。问题消失了。

相关内容