
我創建了一個 systemd 服務來在使用者模式下運行 Gui 應用程式。
這是我的 .service 文件,位於 ~/.config/systemd/user。
[Unit]
Description=daemon service in user session created for startup ways in linux
[Service]
WorkingDirectory=/home/vipul.gupta/MyWorkspace
ExecStart=/home/vipul.gupta/MyWorkspace/GTKSource
Type=simple
[Install]
WantedBy=graphical-session.target
如果我使用,則會出現 Gui 窗口,Environment=DISPLAY=:0
但我不想使用它,因為該服務在使用者會話中運行,因此它有權顯示。
這些是日誌:
Started daemon service in user session created for startup ways in linux
GTKTest[201583]: Unable to init server: Could not connect: Connection refused
GTKTest[201583]: cannot open display:
systemd[72001]: tallyuserdaemon.service: Main process exited, code=exited, status=1/FAILURE
systemd[72001]: tallyuserdaemon.service: Failed with result 'exit-code'.
我無法弄清楚原因。