Score:0

Can't get cron to open Jar file

ar flag

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?

Michael Hampton avatar
cz flag
Exactly how do you execute the script that works?
eggzaile avatar
ar flag
@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"
Score:0
cz flag

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.

eggzaile avatar
ar flag
Thanks for helping me! i changed my script: cd /home/eggzaile/minecraft && java however, nothing happens now, it doesnt start at reboot :s
eggzaile avatar
ar flag
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 avatar
ar flag
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 avatar
ar flag
Nevermind, its working!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.