How to execute script just before x server stop or gnome logout?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
Chrome shows "didn't close correctly" message every time on my Fedora 28 system. I turn off the "Continue running background apps when Google Chrome is closed" feature.
I think the problem is my script executed after the x server stop or gnome logout. That's why chrome and other app close incorrectly still.
The script works fine manually, however, I want to do it automatically. I tried three ways to achieve this.
Close-all-windows Script:
#!/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
I also made soft links to rc6.d
,rc0.d
and 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
init script:
$ cat /etc/init.d/pkillChrome
#!/bin/bash
#pkill -o chrome
#pkill -f chrome
su - fink168 -c /home/fink168/bin/close-all-windows
None of these approaches works on my Fedora 28. What's wrong?
linux fedora gnome chrome x-server
migrated from serverfault.com Jul 29 at 6:17
This question came from our site for system and network administrators.
add a comment |Â
up vote
3
down vote
favorite
Chrome shows "didn't close correctly" message every time on my Fedora 28 system. I turn off the "Continue running background apps when Google Chrome is closed" feature.
I think the problem is my script executed after the x server stop or gnome logout. That's why chrome and other app close incorrectly still.
The script works fine manually, however, I want to do it automatically. I tried three ways to achieve this.
Close-all-windows Script:
#!/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
I also made soft links to rc6.d
,rc0.d
and 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
init script:
$ cat /etc/init.d/pkillChrome
#!/bin/bash
#pkill -o chrome
#pkill -f chrome
su - fink168 -c /home/fink168/bin/close-all-windows
None of these approaches works on my Fedora 28. What's wrong?
linux fedora gnome chrome x-server
migrated from serverfault.com Jul 29 at 6:17
This question came from our site for system and network administrators.
Are you sure Xorg is still running when your script runs automatically?
â dsstorefile1
Jul 29 at 7:58
not sure.but I use gsm postsession default too
â Alexis Li
Jul 29 at 12:33
Might be your profile, try deleting it and making a new one - askubuntu.com/questions/248496/â¦.
â slmâ¦
Jul 29 at 22:55
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
Chrome shows "didn't close correctly" message every time on my Fedora 28 system. I turn off the "Continue running background apps when Google Chrome is closed" feature.
I think the problem is my script executed after the x server stop or gnome logout. That's why chrome and other app close incorrectly still.
The script works fine manually, however, I want to do it automatically. I tried three ways to achieve this.
Close-all-windows Script:
#!/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
I also made soft links to rc6.d
,rc0.d
and 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
init script:
$ cat /etc/init.d/pkillChrome
#!/bin/bash
#pkill -o chrome
#pkill -f chrome
su - fink168 -c /home/fink168/bin/close-all-windows
None of these approaches works on my Fedora 28. What's wrong?
linux fedora gnome chrome x-server
Chrome shows "didn't close correctly" message every time on my Fedora 28 system. I turn off the "Continue running background apps when Google Chrome is closed" feature.
I think the problem is my script executed after the x server stop or gnome logout. That's why chrome and other app close incorrectly still.
The script works fine manually, however, I want to do it automatically. I tried three ways to achieve this.
Close-all-windows Script:
#!/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
I also made soft links to rc6.d
,rc0.d
and 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
init script:
$ cat /etc/init.d/pkillChrome
#!/bin/bash
#pkill -o chrome
#pkill -f chrome
su - fink168 -c /home/fink168/bin/close-all-windows
None of these approaches works on my Fedora 28. What's wrong?
linux fedora gnome chrome x-server
edited Jul 30 at 12:48
asked Jul 29 at 5:25
Alexis Li
163
163
migrated from serverfault.com Jul 29 at 6:17
This question came from our site for system and network administrators.
migrated from serverfault.com Jul 29 at 6:17
This question came from our site for system and network administrators.
Are you sure Xorg is still running when your script runs automatically?
â dsstorefile1
Jul 29 at 7:58
not sure.but I use gsm postsession default too
â Alexis Li
Jul 29 at 12:33
Might be your profile, try deleting it and making a new one - askubuntu.com/questions/248496/â¦.
â slmâ¦
Jul 29 at 22:55
add a comment |Â
Are you sure Xorg is still running when your script runs automatically?
â dsstorefile1
Jul 29 at 7:58
not sure.but I use gsm postsession default too
â Alexis Li
Jul 29 at 12:33
Might be your profile, try deleting it and making a new one - askubuntu.com/questions/248496/â¦.
â slmâ¦
Jul 29 at 22:55
Are you sure Xorg is still running when your script runs automatically?
â dsstorefile1
Jul 29 at 7:58
Are you sure Xorg is still running when your script runs automatically?
â dsstorefile1
Jul 29 at 7:58
not sure.but I use gsm postsession default too
â Alexis Li
Jul 29 at 12:33
not sure.but I use gsm postsession default too
â Alexis Li
Jul 29 at 12:33
Might be your profile, try deleting it and making a new one - askubuntu.com/questions/248496/â¦.
â slmâ¦
Jul 29 at 22:55
Might be your profile, try deleting it and making a new one - askubuntu.com/questions/248496/â¦.
â slmâ¦
Jul 29 at 22:55
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
try to use the graphical
target -- that might fix this.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
try to use the graphical
target -- that might fix this.
add a comment |Â
up vote
1
down vote
try to use the graphical
target -- that might fix this.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
try to use the graphical
target -- that might fix this.
try to use the graphical
target -- that might fix this.
edited Jul 30 at 11:07
Jeff Schaller
30.7k846104
30.7k846104
answered Jul 30 at 10:32
Andre Ciou
111
111
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f459133%2fhow-to-execute-script-just-before-x-server-stop-or-gnome-logout%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Are you sure Xorg is still running when your script runs automatically?
â dsstorefile1
Jul 29 at 7:58
not sure.but I use gsm postsession default too
â Alexis Li
Jul 29 at 12:33
Might be your profile, try deleting it and making a new one - askubuntu.com/questions/248496/â¦.
â slmâ¦
Jul 29 at 22:55