How to execute script just before x server stop or gnome logout?

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question













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
















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?







share|improve this question













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












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?







share|improve this question













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?









share|improve this question












share|improve this question




share|improve this question








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
















  • 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










1 Answer
1






active

oldest

votes

















up vote
1
down vote













try to use the graphical target -- that might fix this.






share|improve this answer























    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    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






























    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.






    share|improve this answer



























      up vote
      1
      down vote













      try to use the graphical target -- that might fix this.






      share|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        try to use the graphical target -- that might fix this.






        share|improve this answer















        try to use the graphical target -- that might fix this.







        share|improve this answer















        share|improve this answer



        share|improve this answer








        edited Jul 30 at 11:07









        Jeff Schaller

        30.7k846104




        30.7k846104











        answered Jul 30 at 10:32









        Andre Ciou

        111




        111






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay