0

I'm running a minecraft server on ubuntu 20.04. I have a script to execute it and works fine. However i can't get it to work @reboot with cron, because it can't find the jar file. From what i researched, it seems cron doesn't run with my user (although i'm not using sudo). What are my options?

This is my crontab -e:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 

00 01 * * * /home/eggzaile/minecraft/backup.sh 2>>&1 

@reboot sleep 45 && /usr/bin/screen -dmS minecraft sh -c '/home/eggzaile/minecraft/start.sh; exec bash' 2>>&1

after the reboot and cron kicks in, when i attach to that window...all i see is the error about not finding the jar file.

this is the script itself:

    #!/bin/sh
while true
do
java -Xms3G -Xmx3G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar paper-1.16.5-778.jar nogui
sleep 5
done

I red somehere that using the full path on the script should work, but that breaks it, i tried. i used (java -jar /path/to/server.jar and all the arguments here), but apparently i should not change the order.

Any tips?

2
  • Exactly how do you execute the script that works? Jun 26, 2021 at 8:27
  • @MichaelHampton just by executing "sh start.sh" it works. However i always open a screen first, to keep it running in the background "screen -S minecraft"
    – eggzaile
    Jun 26, 2021 at 8:28

1 Answer 1

0

Your bash script didn't change into the directory that contains the jar files. That's why your bash script doesn't work. But you did change directory when you started it manually.

Edit your bash script to change to the proper directory before calling java.

4
  • Thanks for helping me! i changed my script: cd /home/eggzaile/minecraft && java however, nothing happens now, it doesnt start at reboot :s
    – eggzaile
    Jun 26, 2021 at 8:43
  • Just to be clear, sitting at home directory ( not where script is ) , executing the cronjob line, works: /usr/bin/screen -dmS minecraft sh -c '/home/eggzaile/minecraft/start.sh; exec bash' Not working at reboot though
    – eggzaile
    Jun 26, 2021 at 8:51
  • Also, i can't figure why isn't doing anything through logs: Jun 26 09:56:06 homelabs CRON[860]: (eggzaile) CMD (sleep 60 && /usr/bin/screen -dmS minecraft sh -c '/home/eggzaile/minecraft/start.sh; exec bash' 2>>&1) Jun 26 09:56:06 homelabs CRON[775]: (CRON) info (No MTA installed, discarding output)
    – eggzaile
    Jun 26, 2021 at 9:00
  • Nevermind, its working!
    – eggzaile
    Jun 26, 2021 at 9:58

You must log in to answer this question.

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