我在
custom_start.service
文件夹中有一个 /etc/systemd/system
文件
[Unit]
Description=System Logging Service
[Service]
User=ABC
ExecStart=/usr/bin/python3 -c "import os;os.system('cd /home/ABC/Desktop;gnome-terminal -e \"bash -c ./efg\"')"
[Install]
WantedBy=multi-user.target
我已于
systemctl start custom_start.service
开始这项服务。
运行时
systemctl status custom_start.service
。
出现以下输出:
● custom_start.service - System Logging Service
Loaded: loaded (/etc/systemd/system/custom_start.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Feb 19 15:58:00 localhost.localdomain systemd[1]: Started System Logging Service.
Feb 19 15:58:00 localhost.localdomain python3[6756]: Unable to init server: Could not connect: Connection refused
Feb 19 15:58:00 localhost.localdomain python3[6756]: # Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
Feb 19 15:58:00 localhost.localdomain python3[6756]: # Use “-- ” to terminate the options and put the command line to execute after it.
Feb 19 15:58:00 localhost.localdomain python3[6756]: # Failed to parse arguments: Cannot open display:
如何通过解决上述错误来使服务处于活动状态。
命令
python3 -c "import os;os.system('cd /home/ABC/Desktop;gnome-terminal -e \"bash -c ./efg\"')"
在终端上工作正常。
程序
efg
正在访问以太网。
systemctl enable custom_start.service
在启动时不执行任何操作。
操作系统是redhat 8.2
当您应该只在工作中启动终端时,为什么要使用 Python 在工作中启动终端?此外,没有可以启动 gnome 终端的桌面。
[Service]
User=ABC
WorkingDirectory=/home/ABC/Desktop
ExecStart=bash -c ./efg
可能会更接近您想要的。
我还会注意到“系统日志服务”听起来非常可疑。