Executing .jar File on Startup

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite
1












Hello this is a question pertaining to my Raspberry Pi but since it is a general Linux question, I posted here instead.



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.



If you found that this is a duplicate question of a similar post. Please notify me before downvoting or deleting this post. I have made this post only because I want all these questions answered as one to help those who are googling the same thing. Thank you! And sorry for the disclaimer!







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














up vote
1
down vote

favorite
1












Hello this is a question pertaining to my Raspberry Pi but since it is a general Linux question, I posted here instead.



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.



If you found that this is a duplicate question of a similar post. Please notify me before downvoting or deleting this post. I have made this post only because I want all these questions answered as one to help those who are googling the same thing. Thank you! And sorry for the disclaimer!







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












up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





Hello this is a question pertaining to my Raspberry Pi but since it is a general Linux question, I posted here instead.



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.



If you found that this is a duplicate question of a similar post. Please notify me before downvoting or deleting this post. I have made this post only because I want all these questions answered as one to help those who are googling the same thing. Thank you! And sorry for the disclaimer!







share|improve this question












Hello this is a question pertaining to my Raspberry Pi but since it is a general Linux question, I posted here instead.



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.



If you found that this is a duplicate question of a similar post. Please notify me before downvoting or deleting this post. I have made this post only because I want all these questions answered as one to help those who are googling the same thing. Thank you! And sorry for the disclaimer!









share|improve this question











share|improve this question




share|improve this question










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

















up vote
1
down vote













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',
    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%2f403915%2fexecuting-jar-file-on-startup%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













    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
























      up vote
      1
      down vote













      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






















        up vote
        1
        down vote










        up vote
        1
        down vote









        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















































             


            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













































































            Popular posts from this blog

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

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?