An `/etc/network/if-up.d` script runs, but doesn't launch GUI apps (e.g. firefox-esr)

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
2
down vote

favorite












I need to start firefox-esr once the network is available.



Here's what I've got:



sudo tee "/etc/network/if-up.d/upif" > /dev/null << EOFBOOT
#!/bin/bash
DISPLAY=":0"
if [[ "$IFACE" = "eth0" || "$IFACE" = "wlan0" ]]; then
echo "$(date) $IFACE" >> /var/log/upif
firefox-esr &
fi
EOFBOOT
sudo chmod +x "/etc/network/if-up.d/upif"


I am getting the date and the interface name in my log file, which means the script runs, but firefox-esr doesn't start.



What I've tried:



  • adding DISPLAY=":0"

  • grep -inR "firefox" /var/log

  • using full path to executable, i.e. /usr/bin/firefox-esr

  • using sudo firefox-esr &

  • removing the trailing &

Nothing helped. However, if I put IFACE="eth0" below the shebang and then run sudo /etc/network/if-up.d/upif manually, that exact script you see above does the job and starts firefox.



I am not sure what's the problem there. Spent few hours on it already. Please help!



This is 2018-06-27-raspbian-stretch-lite running Debian 9.4.



P.S. Also I initially had logic checking whether Firefox already runs before attempting to start it, but once I realised Firefox isn't launched at all, I removed it



UPDATE Found a similar problem: Start a GUI in NetworkManager if-up.d script







share|improve this question

























    up vote
    2
    down vote

    favorite












    I need to start firefox-esr once the network is available.



    Here's what I've got:



    sudo tee "/etc/network/if-up.d/upif" > /dev/null << EOFBOOT
    #!/bin/bash
    DISPLAY=":0"
    if [[ "$IFACE" = "eth0" || "$IFACE" = "wlan0" ]]; then
    echo "$(date) $IFACE" >> /var/log/upif
    firefox-esr &
    fi
    EOFBOOT
    sudo chmod +x "/etc/network/if-up.d/upif"


    I am getting the date and the interface name in my log file, which means the script runs, but firefox-esr doesn't start.



    What I've tried:



    • adding DISPLAY=":0"

    • grep -inR "firefox" /var/log

    • using full path to executable, i.e. /usr/bin/firefox-esr

    • using sudo firefox-esr &

    • removing the trailing &

    Nothing helped. However, if I put IFACE="eth0" below the shebang and then run sudo /etc/network/if-up.d/upif manually, that exact script you see above does the job and starts firefox.



    I am not sure what's the problem there. Spent few hours on it already. Please help!



    This is 2018-06-27-raspbian-stretch-lite running Debian 9.4.



    P.S. Also I initially had logic checking whether Firefox already runs before attempting to start it, but once I realised Firefox isn't launched at all, I removed it



    UPDATE Found a similar problem: Start a GUI in NetworkManager if-up.d script







    share|improve this question





















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I need to start firefox-esr once the network is available.



      Here's what I've got:



      sudo tee "/etc/network/if-up.d/upif" > /dev/null << EOFBOOT
      #!/bin/bash
      DISPLAY=":0"
      if [[ "$IFACE" = "eth0" || "$IFACE" = "wlan0" ]]; then
      echo "$(date) $IFACE" >> /var/log/upif
      firefox-esr &
      fi
      EOFBOOT
      sudo chmod +x "/etc/network/if-up.d/upif"


      I am getting the date and the interface name in my log file, which means the script runs, but firefox-esr doesn't start.



      What I've tried:



      • adding DISPLAY=":0"

      • grep -inR "firefox" /var/log

      • using full path to executable, i.e. /usr/bin/firefox-esr

      • using sudo firefox-esr &

      • removing the trailing &

      Nothing helped. However, if I put IFACE="eth0" below the shebang and then run sudo /etc/network/if-up.d/upif manually, that exact script you see above does the job and starts firefox.



      I am not sure what's the problem there. Spent few hours on it already. Please help!



      This is 2018-06-27-raspbian-stretch-lite running Debian 9.4.



      P.S. Also I initially had logic checking whether Firefox already runs before attempting to start it, but once I realised Firefox isn't launched at all, I removed it



      UPDATE Found a similar problem: Start a GUI in NetworkManager if-up.d script







      share|improve this question











      I need to start firefox-esr once the network is available.



      Here's what I've got:



      sudo tee "/etc/network/if-up.d/upif" > /dev/null << EOFBOOT
      #!/bin/bash
      DISPLAY=":0"
      if [[ "$IFACE" = "eth0" || "$IFACE" = "wlan0" ]]; then
      echo "$(date) $IFACE" >> /var/log/upif
      firefox-esr &
      fi
      EOFBOOT
      sudo chmod +x "/etc/network/if-up.d/upif"


      I am getting the date and the interface name in my log file, which means the script runs, but firefox-esr doesn't start.



      What I've tried:



      • adding DISPLAY=":0"

      • grep -inR "firefox" /var/log

      • using full path to executable, i.e. /usr/bin/firefox-esr

      • using sudo firefox-esr &

      • removing the trailing &

      Nothing helped. However, if I put IFACE="eth0" below the shebang and then run sudo /etc/network/if-up.d/upif manually, that exact script you see above does the job and starts firefox.



      I am not sure what's the problem there. Spent few hours on it already. Please help!



      This is 2018-06-27-raspbian-stretch-lite running Debian 9.4.



      P.S. Also I initially had logic checking whether Firefox already runs before attempting to start it, but once I realised Firefox isn't launched at all, I removed it



      UPDATE Found a similar problem: Start a GUI in NetworkManager if-up.d script









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jul 27 at 7:11









      aexl

      1112




      1112




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          The network event scripts run as the root user, but your desktop environment probably (hopefully) isn't.



          This seems like a problematic approach in general. A few things are missing:



          • Firefox should run as your logged in user, not root.

          • Firefox needs to be able to authenticate to the X server to connect to it (see ~/.Xauthority and man xauth).

          • Firefox's environment needs to be set up to work properly in the desktop session (HOME, XDG_RUNTIME_DIR etc.)

          I would suggest trying a different approach, e.g. having the network script communicate network status (via a pipe / temporary file / DBus) to something already running in the user session (launched e.g. from ~/.xinitrc), which then launches GUI apps as needed.






          share|improve this answer





















          • Thank you for your answer. I've managed to make it the initial approach work - turned out to be easier than I thought it would be. I've shared what helped and will mark that as an answer. Upvoted your answer to appreciate the effort and a quick response. Thanks again!
            – aexl
            Jul 27 at 7:38


















          up vote
          0
          down vote













          Thanks to Fadabi Nawi, here's what the answer was:



          su pi -c "DISPLAY=:0.0 /usr/bin/firefox-esr &"


          Key points:



          • su to the actual user you normally use (pi in my case)

          • pass the display number right there (TODO: find out the actual display number instead of assuming it's :0)


          • important use the full path to Firefox executable, instead of firefox-esr





          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%2f458767%2fan-etc-network-if-up-d-script-runs-but-doesnt-launch-gui-apps-e-g-firefox%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













            The network event scripts run as the root user, but your desktop environment probably (hopefully) isn't.



            This seems like a problematic approach in general. A few things are missing:



            • Firefox should run as your logged in user, not root.

            • Firefox needs to be able to authenticate to the X server to connect to it (see ~/.Xauthority and man xauth).

            • Firefox's environment needs to be set up to work properly in the desktop session (HOME, XDG_RUNTIME_DIR etc.)

            I would suggest trying a different approach, e.g. having the network script communicate network status (via a pipe / temporary file / DBus) to something already running in the user session (launched e.g. from ~/.xinitrc), which then launches GUI apps as needed.






            share|improve this answer





















            • Thank you for your answer. I've managed to make it the initial approach work - turned out to be easier than I thought it would be. I've shared what helped and will mark that as an answer. Upvoted your answer to appreciate the effort and a quick response. Thanks again!
              – aexl
              Jul 27 at 7:38















            up vote
            2
            down vote













            The network event scripts run as the root user, but your desktop environment probably (hopefully) isn't.



            This seems like a problematic approach in general. A few things are missing:



            • Firefox should run as your logged in user, not root.

            • Firefox needs to be able to authenticate to the X server to connect to it (see ~/.Xauthority and man xauth).

            • Firefox's environment needs to be set up to work properly in the desktop session (HOME, XDG_RUNTIME_DIR etc.)

            I would suggest trying a different approach, e.g. having the network script communicate network status (via a pipe / temporary file / DBus) to something already running in the user session (launched e.g. from ~/.xinitrc), which then launches GUI apps as needed.






            share|improve this answer





















            • Thank you for your answer. I've managed to make it the initial approach work - turned out to be easier than I thought it would be. I've shared what helped and will mark that as an answer. Upvoted your answer to appreciate the effort and a quick response. Thanks again!
              – aexl
              Jul 27 at 7:38













            up vote
            2
            down vote










            up vote
            2
            down vote









            The network event scripts run as the root user, but your desktop environment probably (hopefully) isn't.



            This seems like a problematic approach in general. A few things are missing:



            • Firefox should run as your logged in user, not root.

            • Firefox needs to be able to authenticate to the X server to connect to it (see ~/.Xauthority and man xauth).

            • Firefox's environment needs to be set up to work properly in the desktop session (HOME, XDG_RUNTIME_DIR etc.)

            I would suggest trying a different approach, e.g. having the network script communicate network status (via a pipe / temporary file / DBus) to something already running in the user session (launched e.g. from ~/.xinitrc), which then launches GUI apps as needed.






            share|improve this answer













            The network event scripts run as the root user, but your desktop environment probably (hopefully) isn't.



            This seems like a problematic approach in general. A few things are missing:



            • Firefox should run as your logged in user, not root.

            • Firefox needs to be able to authenticate to the X server to connect to it (see ~/.Xauthority and man xauth).

            • Firefox's environment needs to be set up to work properly in the desktop session (HOME, XDG_RUNTIME_DIR etc.)

            I would suggest trying a different approach, e.g. having the network script communicate network status (via a pipe / temporary file / DBus) to something already running in the user session (launched e.g. from ~/.xinitrc), which then launches GUI apps as needed.







            share|improve this answer













            share|improve this answer



            share|improve this answer











            answered Jul 27 at 7:30









            Vladimir Panteleev

            719416




            719416











            • Thank you for your answer. I've managed to make it the initial approach work - turned out to be easier than I thought it would be. I've shared what helped and will mark that as an answer. Upvoted your answer to appreciate the effort and a quick response. Thanks again!
              – aexl
              Jul 27 at 7:38

















            • Thank you for your answer. I've managed to make it the initial approach work - turned out to be easier than I thought it would be. I've shared what helped and will mark that as an answer. Upvoted your answer to appreciate the effort and a quick response. Thanks again!
              – aexl
              Jul 27 at 7:38
















            Thank you for your answer. I've managed to make it the initial approach work - turned out to be easier than I thought it would be. I've shared what helped and will mark that as an answer. Upvoted your answer to appreciate the effort and a quick response. Thanks again!
            – aexl
            Jul 27 at 7:38





            Thank you for your answer. I've managed to make it the initial approach work - turned out to be easier than I thought it would be. I've shared what helped and will mark that as an answer. Upvoted your answer to appreciate the effort and a quick response. Thanks again!
            – aexl
            Jul 27 at 7:38













            up vote
            0
            down vote













            Thanks to Fadabi Nawi, here's what the answer was:



            su pi -c "DISPLAY=:0.0 /usr/bin/firefox-esr &"


            Key points:



            • su to the actual user you normally use (pi in my case)

            • pass the display number right there (TODO: find out the actual display number instead of assuming it's :0)


            • important use the full path to Firefox executable, instead of firefox-esr





            share|improve this answer

























              up vote
              0
              down vote













              Thanks to Fadabi Nawi, here's what the answer was:



              su pi -c "DISPLAY=:0.0 /usr/bin/firefox-esr &"


              Key points:



              • su to the actual user you normally use (pi in my case)

              • pass the display number right there (TODO: find out the actual display number instead of assuming it's :0)


              • important use the full path to Firefox executable, instead of firefox-esr





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Thanks to Fadabi Nawi, here's what the answer was:



                su pi -c "DISPLAY=:0.0 /usr/bin/firefox-esr &"


                Key points:



                • su to the actual user you normally use (pi in my case)

                • pass the display number right there (TODO: find out the actual display number instead of assuming it's :0)


                • important use the full path to Firefox executable, instead of firefox-esr





                share|improve this answer













                Thanks to Fadabi Nawi, here's what the answer was:



                su pi -c "DISPLAY=:0.0 /usr/bin/firefox-esr &"


                Key points:



                • su to the actual user you normally use (pi in my case)

                • pass the display number right there (TODO: find out the actual display number instead of assuming it's :0)


                • important use the full path to Firefox executable, instead of firefox-esr






                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered Jul 27 at 7:32









                aexl

                1112




                1112






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f458767%2fan-etc-network-if-up-d-script-runs-but-doesnt-launch-gui-apps-e-g-firefox%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