Executing .jar File on Startup












1














I'm running a Nukkit Minecraft server on my Raspberry Pi (I know it doesn't have good hardware but I'm experimenting) and googling different ways to make a bash file for Linux. I have made the file startNukkit.whateverextension. I have come to this:



!#/bin/bash/

gnome-terminal -e "java -jar home/pi/Desktop/Nukkit/nukkit.jar; exec bash""


But there are multiple things I want to solve. First, when I double click the bash file it will prompt me to: "Execute", "Execute in Terminal", "Open", and "Cancel". Instead, I would like to run it right away without this prompt.



And because this is a Minecraft server, I can only see the results of the server in the terminal, such as who connects to my server. But if I click on "Execute in Terminal", the terminal will show and then close. I thought this could be solved by "exec bash"" as explained here. To keep the terminal window open.



And finally, I would like to make this execute in startup similar to how in Windows has a startup folder where any file you place in this folder will execute in startup.










share|improve this question




















  • 2




    It should be#!, not !#.
    – G-Man
    Nov 11 '17 at 15:29










  • My apologies I didn't notice! But when I go to make the change the terminal window is blank. What else am I doing wrong?
    – Mr. El
    Nov 11 '17 at 15:30












  • You can put your command in /home/pi/.config/lxsession/LXDE-pi/autostart file. Commands in this script are executed on every boot.
    – Arpit Agarwal
    Nov 11 '17 at 16:04
















1














I'm running a Nukkit Minecraft server on my Raspberry Pi (I know it doesn't have good hardware but I'm experimenting) and googling different ways to make a bash file for Linux. I have made the file startNukkit.whateverextension. I have come to this:



!#/bin/bash/

gnome-terminal -e "java -jar home/pi/Desktop/Nukkit/nukkit.jar; exec bash""


But there are multiple things I want to solve. First, when I double click the bash file it will prompt me to: "Execute", "Execute in Terminal", "Open", and "Cancel". Instead, I would like to run it right away without this prompt.



And because this is a Minecraft server, I can only see the results of the server in the terminal, such as who connects to my server. But if I click on "Execute in Terminal", the terminal will show and then close. I thought this could be solved by "exec bash"" as explained here. To keep the terminal window open.



And finally, I would like to make this execute in startup similar to how in Windows has a startup folder where any file you place in this folder will execute in startup.










share|improve this question




















  • 2




    It should be#!, not !#.
    – G-Man
    Nov 11 '17 at 15:29










  • My apologies I didn't notice! But when I go to make the change the terminal window is blank. What else am I doing wrong?
    – Mr. El
    Nov 11 '17 at 15:30












  • You can put your command in /home/pi/.config/lxsession/LXDE-pi/autostart file. Commands in this script are executed on every boot.
    – Arpit Agarwal
    Nov 11 '17 at 16:04














1












1








1


1





I'm running a Nukkit Minecraft server on my Raspberry Pi (I know it doesn't have good hardware but I'm experimenting) and googling different ways to make a bash file for Linux. I have made the file startNukkit.whateverextension. I have come to this:



!#/bin/bash/

gnome-terminal -e "java -jar home/pi/Desktop/Nukkit/nukkit.jar; exec bash""


But there are multiple things I want to solve. First, when I double click the bash file it will prompt me to: "Execute", "Execute in Terminal", "Open", and "Cancel". Instead, I would like to run it right away without this prompt.



And because this is a Minecraft server, I can only see the results of the server in the terminal, such as who connects to my server. But if I click on "Execute in Terminal", the terminal will show and then close. I thought this could be solved by "exec bash"" as explained here. To keep the terminal window open.



And finally, I would like to make this execute in startup similar to how in Windows has a startup folder where any file you place in this folder will execute in startup.










share|improve this question















I'm running a Nukkit Minecraft server on my Raspberry Pi (I know it doesn't have good hardware but I'm experimenting) and googling different ways to make a bash file for Linux. I have made the file startNukkit.whateverextension. I have come to this:



!#/bin/bash/

gnome-terminal -e "java -jar home/pi/Desktop/Nukkit/nukkit.jar; exec bash""


But there are multiple things I want to solve. First, when I double click the bash file it will prompt me to: "Execute", "Execute in Terminal", "Open", and "Cancel". Instead, I would like to run it right away without this prompt.



And because this is a Minecraft server, I can only see the results of the server in the terminal, such as who connects to my server. But if I click on "Execute in Terminal", the terminal will show and then close. I thought this could be solved by "exec bash"" as explained here. To keep the terminal window open.



And finally, I would like to make this execute in startup similar to how in Windows has a startup folder where any file you place in this folder will execute in startup.







shell-script startup






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 16 at 22:03









Rui F Ribeiro

38.9k1479129




38.9k1479129










asked Nov 11 '17 at 15:17









Mr. El

63




63








  • 2




    It should be#!, not !#.
    – G-Man
    Nov 11 '17 at 15:29










  • My apologies I didn't notice! But when I go to make the change the terminal window is blank. What else am I doing wrong?
    – Mr. El
    Nov 11 '17 at 15:30












  • You can put your command in /home/pi/.config/lxsession/LXDE-pi/autostart file. Commands in this script are executed on every boot.
    – Arpit Agarwal
    Nov 11 '17 at 16:04














  • 2




    It should be#!, not !#.
    – G-Man
    Nov 11 '17 at 15:29










  • My apologies I didn't notice! But when I go to make the change the terminal window is blank. What else am I doing wrong?
    – Mr. El
    Nov 11 '17 at 15:30












  • You can put your command in /home/pi/.config/lxsession/LXDE-pi/autostart file. Commands in this script are executed on every boot.
    – Arpit Agarwal
    Nov 11 '17 at 16:04








2




2




It should be#!, not !#.
– G-Man
Nov 11 '17 at 15:29




It should be#!, not !#.
– G-Man
Nov 11 '17 at 15:29












My apologies I didn't notice! But when I go to make the change the terminal window is blank. What else am I doing wrong?
– Mr. El
Nov 11 '17 at 15:30






My apologies I didn't notice! But when I go to make the change the terminal window is blank. What else am I doing wrong?
– Mr. El
Nov 11 '17 at 15:30














You can put your command in /home/pi/.config/lxsession/LXDE-pi/autostart file. Commands in this script are executed on every boot.
– Arpit Agarwal
Nov 11 '17 at 16:04




You can put your command in /home/pi/.config/lxsession/LXDE-pi/autostart file. Commands in this script are executed on every boot.
– Arpit Agarwal
Nov 11 '17 at 16:04










1 Answer
1






active

oldest

votes


















1














As a systemd service



(You didn't mention a specific GNU/Linux distribution, I think most common ones have systemd available though)



If you move your .jar file to some accessible place like /opt then you could have systemd run your server after startup as nobody or some other low-privilege user.



In addition to potentially running without access to home directories, etc. you can also configure systemd to restart a service after failure and many other things.



See man systemd.service, man systemd.exec, man systemd.unit, etc.




nukkit.service



[Unit]
Description=Nukkit Server
After=syslog.target
After=network.target

[Service]
Type=simple
User=nobody
Group=nobody
ExecStart=java -jar /opt/Nukkit/nukkit.jar

[Install]
WantedBy=multi-user.target


Watching output



Where you have /etc/systemd/system/nukkit.service and have:




  • systemctl enable nukkit

  • systemctl start nukkit


then journalctl -f -u nukkit should follow the most recent log messages from systemd unit nukkit. Your system may be using syslog or some other facility though; in that case you could configure logging to a specific file, etc.






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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    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%2f403915%2fexecuting-jar-file-on-startup%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    As a systemd service



    (You didn't mention a specific GNU/Linux distribution, I think most common ones have systemd available though)



    If you move your .jar file to some accessible place like /opt then you could have systemd run your server after startup as nobody or some other low-privilege user.



    In addition to potentially running without access to home directories, etc. you can also configure systemd to restart a service after failure and many other things.



    See man systemd.service, man systemd.exec, man systemd.unit, etc.




    nukkit.service



    [Unit]
    Description=Nukkit Server
    After=syslog.target
    After=network.target

    [Service]
    Type=simple
    User=nobody
    Group=nobody
    ExecStart=java -jar /opt/Nukkit/nukkit.jar

    [Install]
    WantedBy=multi-user.target


    Watching output



    Where you have /etc/systemd/system/nukkit.service and have:




    • systemctl enable nukkit

    • systemctl start nukkit


    then journalctl -f -u nukkit should follow the most recent log messages from systemd unit nukkit. Your system may be using syslog or some other facility though; in that case you could configure logging to a specific file, etc.






    share|improve this answer


























      1














      As a systemd service



      (You didn't mention a specific GNU/Linux distribution, I think most common ones have systemd available though)



      If you move your .jar file to some accessible place like /opt then you could have systemd run your server after startup as nobody or some other low-privilege user.



      In addition to potentially running without access to home directories, etc. you can also configure systemd to restart a service after failure and many other things.



      See man systemd.service, man systemd.exec, man systemd.unit, etc.




      nukkit.service



      [Unit]
      Description=Nukkit Server
      After=syslog.target
      After=network.target

      [Service]
      Type=simple
      User=nobody
      Group=nobody
      ExecStart=java -jar /opt/Nukkit/nukkit.jar

      [Install]
      WantedBy=multi-user.target


      Watching output



      Where you have /etc/systemd/system/nukkit.service and have:




      • systemctl enable nukkit

      • systemctl start nukkit


      then journalctl -f -u nukkit should follow the most recent log messages from systemd unit nukkit. Your system may be using syslog or some other facility though; in that case you could configure logging to a specific file, etc.






      share|improve this answer
























        1












        1








        1






        As a systemd service



        (You didn't mention a specific GNU/Linux distribution, I think most common ones have systemd available though)



        If you move your .jar file to some accessible place like /opt then you could have systemd run your server after startup as nobody or some other low-privilege user.



        In addition to potentially running without access to home directories, etc. you can also configure systemd to restart a service after failure and many other things.



        See man systemd.service, man systemd.exec, man systemd.unit, etc.




        nukkit.service



        [Unit]
        Description=Nukkit Server
        After=syslog.target
        After=network.target

        [Service]
        Type=simple
        User=nobody
        Group=nobody
        ExecStart=java -jar /opt/Nukkit/nukkit.jar

        [Install]
        WantedBy=multi-user.target


        Watching output



        Where you have /etc/systemd/system/nukkit.service and have:




        • systemctl enable nukkit

        • systemctl start nukkit


        then journalctl -f -u nukkit should follow the most recent log messages from systemd unit nukkit. Your system may be using syslog or some other facility though; in that case you could configure logging to a specific file, etc.






        share|improve this answer












        As a systemd service



        (You didn't mention a specific GNU/Linux distribution, I think most common ones have systemd available though)



        If you move your .jar file to some accessible place like /opt then you could have systemd run your server after startup as nobody or some other low-privilege user.



        In addition to potentially running without access to home directories, etc. you can also configure systemd to restart a service after failure and many other things.



        See man systemd.service, man systemd.exec, man systemd.unit, etc.




        nukkit.service



        [Unit]
        Description=Nukkit Server
        After=syslog.target
        After=network.target

        [Service]
        Type=simple
        User=nobody
        Group=nobody
        ExecStart=java -jar /opt/Nukkit/nukkit.jar

        [Install]
        WantedBy=multi-user.target


        Watching output



        Where you have /etc/systemd/system/nukkit.service and have:




        • systemctl enable nukkit

        • systemctl start nukkit


        then journalctl -f -u nukkit should follow the most recent log messages from systemd unit nukkit. Your system may be using syslog or some other facility though; in that case you could configure logging to a specific file, etc.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 '17 at 1:20









        Andrew Siplas

        1815




        1815






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f403915%2fexecuting-jar-file-on-startup%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Morgemoulin

            Scott Moir

            Souastre