Systemd服务的行为与手动执行ExecStart命令相似

时间:2018-12-20 12:48:30

标签: service systemd

我在systemd中启用了pcieserver.service,它会触发/opt/pcieserver/pcieserver.sh脚本,并且看起来工作正常。

我面临的一个问题是,该服务器使用nc(netcat)读取套接字并将数据转储到/ tmp / temp文件中;如果我使用sudo /opt/pcieserver/pcieserver.sh命令运行此脚本,然后触发nc转储数据,则会创建临时文件,并按预期转储数据。如果我从systemd服务运行时触发了nc,它将生成文件,但是没有转储数据,即始终保持为0kb。

位于/etc/systemd/system/pcieserver.service下的systemd服务文件

内容:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=PCIe-Server
After=network.target

[Service]
Type=simple

ExecStart=/opt/pcieserver/pcieserver.sh
Restart=on-failure
RestartSec=30

[Install]
WantedBy=multi-user.target

pcieserver.sh内容:

# Getting Script Directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

cd ${SCRIPT_DIR}
/usr/bin/sudo python ${SCRIPT_DIR}/pcieserver.py

journalctl输出:

pcieserver.startLocalTrace[26859]: startLocalTrace function...
pcieserver.sh[26851]: 2018-12-24 06:57:38,169 startLocalTrace function...
pcieserver.sh[26851]: 2018-12-24 06:57:38,170 Delete local Trace:/tmp/trace
pcieserver.deleteLocalTrace[26859]: Delete local Trace:/tmp/trace
pcieserver.sh[26851]: 2018-12-24 06:57:38,170 Tracefile /tmp/trace exists, delete...
pcieserver.deleteLocalTrace[26859]: Tracefile /tmp/trace exists, delete...
pcieserver.sh[26851]: 2018-12-24 06:57:38,170 Tracefile /tmp/trace exists, delete...done
pcieserver.sh[26851]: 2018-12-24 06:57:38,170 Start local Trace to file /tmp/trace...
pcieserver.deleteLocalTrace[26859]: Tracefile /tmp/trace exists, delete...done
pcieserver.sh[26851]: 2018-12-24 06:57:38,170 Start local Trace to file /tmp/trace. Command:nc 127.0.0.1 4705 >/tmp/trace
pcieserver.sh[26851]: 2018-12-24 06:57:38,170 Start process:nc 127.0.0.1 4705 >/tmp/trace
pcieserver.startLocalTrace[26859]: Start local Trace to file /tmp/trace...
pcieserver.startLocalTrace[26859]: Start local Trace to file /tmp/trace. Command:nc 127.0.0.1 4705 >/tmp/trace
pcieserver.startProcess[26859]: Start process:nc 127.0.0.1 4705 >/tmp/trace
pcieserver.startLocalTrace[26859]: Start local Trace to file /tmp/trace...started
pcieserver.sh[26851]: 2018-12-24 06:57:38,176 Start local Trace to file /tmp/trace...started
sudo[4121]:     root : TTY=unknown ; PWD=/opt/pcieserver ; USER=root ; COMMAND=/bin/nc 127.0.0.1 4705
sudo[4121]: pam_unix(sudo:session): session opened for user root by (uid=0)

P.S。我检查了两种情况下的权限是否相同。

0 个答案:

没有答案