แอปพลิเคชัน. desktop ที่รีสตาร์ทโดยอัตโนมัติจะไม่ออกเมื่อออกจากระบบ

Jun 17 2020

ฉันกำลังติดตามคำตอบของแอปพลิเคชัน Autostarting .desktop เมื่อเริ่มต้นไม่ทำงานและทำงานได้ดี ฉันกำลังเปิดตัวสคริปต์ python .desktopแอพลิเคชันมีลักษณะเช่นนี้

[Desktop Entry]
Type=Application
Name=Autostart Script
Exec=shutdown_notify.py
Icon=system-run

สิ่งนี้ใช้งานได้ดี - แต่ถ้าฉันออกจากระบบและเข้าสู่ระบบฉันเห็นว่าสคริปต์ของฉันยังคงทำงานอยู่

$ ps -C shutdown_notify.py
  PID TTY          TIME CMD
 4026 ?        00:00:01 shutdown_notify
25421 ?        00:00:00 shutdown_notify

มีวิธีตรวจสอบให้แน่ใจว่าสคริปต์ออกเมื่อออกจากระบบหรือไม่? ฉันต้องเพิ่มตรรกะเพื่อออกจากระบบหรือไม่?


อัปเดตlogind.confข้อมูลตามที่ @binarysta ร้องขอ

$ grep -E 'KillUserProcesses|KillOnlyUsers|KillExcludeUsers' /etc/systemd/logind.conf
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root

Update, ฉันมีสองไฟล์ autostart: gnome-terminalหนึ่งในการเปิดตัวสคริปต์หลามข้างต้นเปิดตัวอื่น หลังจากรีบูตฉันเห็น:

$ ps aux | grep -E "gnome-terminal|shutdown_notify"
training  6495  0.9  0.1  84936 29360 ?        S    07:13   0:00 /usr/bin/python3 /usr/local/bin/shutdown_notify.py
training  6565  0.7  0.2 622880 34448 ?        Sl   07:13   0:00 /usr/lib/gnome-terminal/gnome-terminal-server
training  9647  0.0  0.0  13264  2564 pts/0    S+   07:13   0:00 grep --color=auto -E gnome-terminal|shutdown_notify

ออกจากระบบเข้าสู่ระบบและฉันเห็น:

training  6495  0.1  0.1  85076 29360 ?        S    07:13   0:00 /usr/bin/python3 /usr/local/bin/shutdown_notify.py
training 19110  3.1  0.1  84936 29636 ?        S    07:15   0:00 /usr/bin/python3 /usr/local/bin/shutdown_notify.py
training 19141  2.3  0.2 696496 34584 ?        Sl   07:15   0:00 /usr/lib/gnome-terminal/gnome-terminal-server
training 19421  0.0  0.0  13264  2696 pts/0    S+   07:15   0:00 grep --color=auto -E gnome-terminal|shutdown_notify

คำตอบ

1 binarysta Jun 18 2020 at 12:56

นี้เป็นเพราะKillUserProcessesเป็นnoโดยเริ่มต้นในอูบุนตู การตั้งค่านี้ทำให้กระบวนการของผู้ใช้ไม่ถูกฆ่าเมื่อผู้ใช้ออกจากระบบโดยสมบูรณ์ ในการเปลี่ยนพฤติกรรมนี้เพื่อให้มีการใช้กระบวนการฆ่าตายทั้งหมดออกจากระบบของผู้ใช้ตั้งค่าKillUserProcesses=yesใน/etc/systemd/logind.confและใหม่เข้าสู่ระบบ

ค่าปัจจุบันสามารถตรวจสอบได้โดย (ควรเป็นค่าtrueหลังการเปลี่ยนแปลง)

busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager KillUserProcesses
b true

อัปเดต

ความแตกต่างระหว่างgnome-terminal(แอปพลิเคชัน GUI) และshutdown_notify.pyกระบวนการคือgnome-terminal-serverกระบวนการที่เชื่อมโยงกับ TTY เดียวกันกับกระบวนการ X11 อื่น ๆ ทั้งหมดที่ทำงานอยู่ เมื่อออกจากระบบสภาพแวดล้อมเดสก์ท็อปและระบบหน้าต่าง (x11) จะถูกยกเลิกดังนั้นจึงgnome-terminalออกจากระบบ