在 Centos 7 系统上设置 systemd 服务时出现问题

在 Centos 7 系统上设置 systemd 服务时出现问题

供应商的应用程序是使用非 root 用户安装的。这得到了供应商的支持,一切都很好。因此,非 root 用户拥有所有已安装的应用程序可执行文件和文件。软件要求之一是在将使用该产品的任何用户配置文件中设置环境变量。在非 root 安装中,只有安装它的用户才会使用它,因此我在以下文件中定义了以下内容.bash_profile

export CFROOT=/usr/opt/tibco/mft/ps

然后我有

export PATH=$CFROOT:$PATH

一切都很好。用户可以登录并启动守护进程,一切顺利。用户也可以注销,守护进程将继续运行。

我希望该产品在启动时启动,从而无需以该用户身份登录并启动它。

mftps.service在目录中创建了一个文件/usr/lib/systemd/system

服务文件包含以下设置:

[Unit]
Description=MFT Platform Server Service
After=network.target

[Service]
Type=simple
User=tibcomft
EnvironmentFile=/etc/sysconfig/mftps
ExecStart=/usr/opt/tibco/mft/ps/cfstart
ExecStop=/usr/opt/tibco/mft/ps/cfstop
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

注意:在添加之前,我会不断收到未定义的EnvironmentFile错误。CFROOT在研究设置时,我找到了相关信息并添加了文件/etc/sysconfig/mftps。在此 sysconfig 文件中,我有以下内容:

CFROOT=/usr/opt/tibco/mft/ps
export CFROOT

注意:上述设置是我使 sysconfig 文件正常工作的唯一方法。例如,如果我有任何带有“$”的内容,export PATH=$CFROOT:$PATH则会systemctl start失败。

systemctl start mftps.service那么,当我运行然后显示我看到的状态时,现在发生了什么:

[root@centos72sys jbarker]# systemctl status mftps.service
● mftps.service - MFT Platform Server Service
   Loaded: loaded (/usr/lib/systemd/system/mftps.service; disabled; vendor preset: disabled) 
 Active: inactive (dead)

Jan 13 13:12:11 centos72sys systemd[1]: Started MFT Platform Server Service.
Jan 13 13:12:11 centos72sys systemd[1]: Starting MFT Platform Server Service...
Jan 13 13:12:11 centos72sys cfstart[4237]: MFT Platform Server Responder will be started from /usr/opt/tibco/mft/ps
Jan 13 13:12:12 centos72sys cfstart[4237]: Failed To Start CyberResp process. Read /usr/opt/tibco/mft/ps/FailureReason.txt
[root@centos72sys jbarker]#

当我查看它时,FailureReason.txt它指出以下内容:

cfsend not found in PATH

可执行文件cfsend位于定义的路径中,$CFROOT但当用户运行命令时没有启动任何内容,cfstart所以我不知道为什么它会抛出此错误。

答案1

我遇到了同样的问题,通过在 /etc/sysconfig/mftps 中添加以下行来解决

more /etc/sysconfig/mftps
CFROOT=/apps/opt/mftps
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:/root/bin:/apps/opt/mftps:/apps/opt/mftps/config

more /etc/systemd/system/mftps.service
[Unit]
Description=MFT Platform Server Service
After=network.target

[Service]
Type=forking
User=root
EnvironmentFile=/etc/sysconfig/mftps
ExecStart=/apps/opt/mftps/cfstart
ExecStop=/apps/opt/mftps/cfstop
RemainAfterExit=yes
WorkingDirectory=/apps/opt/mftps

[Install]
WantedBy=multi-user.target

ps -ef | grep Cyb
root     22513     1  0 13:22 ?        00:00:00 /apps/opt/mftps/CyberResp
root     22731 20313  0 13:23 pts/18   00:00:00 grep --color=auto Cyb

systemctl stop mftps.service

ps -ef | grep Cyb
root     25374 20313  0 13:25 pts/18   00:00:00 grep --color=auto Cyb

systemctl start mftps.service
ps -ef | grep Cyb
root     26454     1  0 13:25 ?        00:00:00 /apps/opt/mftps/CyberResp
root     26698 20313  0 13:25 pts/18   00:00:00 grep --color=auto Cyb

相关内容