![x 서버가 중지되거나 gnome이 로그오프하기 전에 스크립트를 실행하는 방법은 무엇입니까?](https://linux55.com/image/137735/x%20%EC%84%9C%EB%B2%84%EA%B0%80%20%EC%A4%91%EC%A7%80%EB%90%98%EA%B1%B0%EB%82%98%20gnome%EC%9D%B4%20%EB%A1%9C%EA%B7%B8%EC%98%A4%ED%94%84%ED%95%98%EA%B8%B0%20%EC%A0%84%EC%97%90%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EB%A5%BC%20%EC%8B%A4%ED%96%89%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
Chrome은 Fedora 28 시스템에서 매번 "제대로 닫히지 않았습니다"라는 메시지를 표시합니다. 'Chrome 종료 시 백그라운드 앱 계속 실행' 기능을 꺼두었습니다.
문제는 x 서버가 중지되거나 gnome이 로그오프된 후에 내 스크립트가 실행된다는 것입니다. 이것이 바로 Chrome 및 기타 앱이 여전히 제대로 닫히지 않는 이유입니다.
스크립트는 수동으로 잘 작동하지만 자동화하고 싶습니다. 나는 이것을 달성하기 위해 세 가지 방법을 시도했습니다.
모든 Windows 스크립트를 닫습니다.
#!/bin/sh
#wmctrl -l | while read -r line
#do
# wmctrl -c `echo "$line" | sed 's/.* [0-9]* [fink168] //'`
#done
WIN_IDs=$(wmctrl -l | awk '$3 != "N/A" {print $1}')
for i in $WIN_IDs; do wmctrl -ic "$i"; done
/etc/systemd/system/closeWindow.service
:
[Unit]
Description=CloseWindows
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target kexec.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/home/fink168/bin/close-all-windows
[Install]
WantedBy=multi-user.target
systemctl status closeWindow.service
● closeWindow.service - CloseWindows
Loaded: loaded (/etc/systemd/system/closeWindow.service; enabled; vendor preset: dis>
Active: active (exited) since Sun 2018-07-29 12:17:58 CST; 1h 4min ago
Process: 619 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 619 (code=exited, status=0/SUCCESS)
Jul 29 12:17:58 fink168 systemd[1]: Started CloseWindows.
/etc/gdm/PostSession/Default
:
#!/bin/sh
echo " Closing selected windows programs gracefully"
#export DISPLAY=$DISPLAY
su - fink168 -c /home/fink168/bin/close-all-windows
#su fink168 -c pkill -o chrome
rc6.d
, rc0.d
및 에 대한 소프트 링크도 만들었습니다 rc5.d
.
$ ls -alrt /etc/rc6.d/
total 8
lrwxrwxrwx. 1 root root 17 Apr 25 14:34 K90network -> ../init.d/network
lrwxrwxrwx. 1 root root 20 Apr 25 14:34 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx. 1 root root 17 Apr 25 14:39 K99livesys -> ../init.d/livesys
lrwxrwxrwx. 1 root root 22 Apr 25 14:39 K01livesys-late -> ../init.d/livesys-late
drwxr-xr-x. 10 root root 4096 Jul 18 19:39 ..
lrwxrwxrwx. 1 root root 23 Jul 28 22:56 K99pkillChrome -> /etc/init.d/pkillChrome
drwxr-xr-x. 2 root root 4096 Jul 28 22:56 .
pkillChrome
초기화 스크립트:
$ cat /etc/init.d/pkillChrome
#!/bin/bash
#pkill -o chrome
#pkill -f chrome
su - fink168 -c /home/fink168/bin/close-all-windows
이러한 방법 중 어느 것도 내 Fedora 28에서는 작동하지 않습니다. 무엇이 잘못되었나요?
답변1
대상을 사용해 보십시오 graphical
. 이렇게 하면 문제가 해결될 수 있습니다.