1

I got myself a minecraft server that turns on and off on specific hours but I don't want to type the commands every time it should start playing and let it run those commands after boot. I found an old askubuntu thread (for 12.04) where this is handled and let it run as root. But for security reasons, I don't want it to run as root. I would like to still be able to type in commands to like stop the server, so it cannot run my bash script somewhere hidden.

2
  • Read man 5 crontab, and use the special @reboot date field.
    – waltinator
    Jun 10, 2021 at 14:54
  • Sounds like you need an ordinary startup script, this should work as a template, with Group=, User= directive you may specify different user, group (I would also recommend /usr/local/lib/systemd/system instead of /etc/systemd/system).
    – user986805
    Jun 11, 2021 at 6:45

2 Answers 2

1

You could try to use a crontab entry for your user.

The command to run a command att boot is "@reboot".

Example of crontab entry:

@reboot   cd /home && sh ./myscript.sh
7
  • And... how can I set that crontab entry?
    – Irsu85
    Jun 10, 2021 at 14:58
  • Run the command crontab -e
    – Level9
    Jun 10, 2021 at 15:09
  • thanks, ill try that tomorrow
    – Irsu85
    Jun 10, 2021 at 15:10
  • 1
    Storing scripts in /home is not common (nor recommended). It's also preferable to use the full path to your command. Specifying the shell on the command line /bin/sh script.sh will pass the interpret directive #! as a regular comment instead of specified interpreter. And if they differ may lead to feature inconsistency.
    – user986805
    Jun 11, 2021 at 6:11
  • My script is also not in home, it's in /home/myUserName/survival
    – Irsu85
    Jun 11, 2021 at 7:43
0

To automatically run a command every time the system boots:

  • Search "Startup Applications" in the dash and open it.

  • Click add. For the name put "Start Minecraft Server" and under "command" put your command used to start your Minecraft server.

  • Press add and now the script should run on restart/startup.

Enjoy!

5
  • If the Ubuntu installation used the server version instead of the desktop version, this will not possible as there's no way to access a GUI program. Although, for cases like these I would recommend a systemd unit as suggested by @bac0n comment's above. As you will most likely want easier control to stop and restart such software.
    – Dan
    Jun 22, 2021 at 13:08
  • Ah gotcha. I just thought I would share this method as a less programming-savy alternative.
    – jackw11111
    Jun 22, 2021 at 13:17
  • 1
    I didn't mean it as the answer is wrong, to complain or anything of the sort. Sorry if it sounded like that! The answer is absolutely fine. But I just wanted to mention it as a "disclaimer" for this specific case.
    – Dan
    Jun 22, 2021 at 13:28
  • @Dan All good, It was a good point I hadn't considered, thankyou! :)
    – jackw11111
    Jun 22, 2021 at 13:39
  • I like this idea, but I can't access a GUI.
    – Irsu85
    Jun 22, 2021 at 14:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .