Closed Dooleylabs closed 7 years ago
Running outside of crontab as a non-web user, assuming you want a 1GB server named "test", and a .jar file named "server.jar", this works:
sudo -Hu www-data screen -dmS mchp-test java -Xincgc -Xms1024M -Xmx2048M -jar server.jar nogui
So to start the server daily at midnight, this works in www-data's crontab:
0 0 * * * screen -dmS mchp-test java -Xincgc -Xms1024M -Xmx2048M -jar server.jar nogui
You can pass commands like this (replacing "stop" with whatever command):
screen -S mchp-test -p 0 -X stuff "stop$(printf \\r)"
Hopefully that's somewhat helpful, I'm not sure what exactly you've tried so far, but I can confirm these work for me on my environment.
Unfortunately, this doesn't work with @reboot
for some reason, though my server does support the @reboot
crontab tag. This is my code in www-data's crontab:
@reboot screen -dmS meoz-hub java -Xincgc -Xms256M -Xmx2048M -jar /home/hub/spigot.jar nogui
So apparently it's very difficult to start anything java with crontab @reboot
Any other ideas?
Maybe use crontab to start a bash script that then waits for a bit and starts Java? I'm not sure what the best option is here.
I'll try a sleep 10 in the script and see if it works. Not a bad idea...
So I made a bash script and placed it in a directory accessible by the web user. The first line of code after the bash identifier is sleep 10
. I tried it with sleep 30
, which worked flawlessly, other than taking 72 seconds to boot, when the server only takes 37 to be operable, which is why I dropped it to 10. As far as I can tell, it works. I'll document it if needed.
Using crontab as www-data, how would I start screen sessions as the web interface would that the web interface would detect? I tried copying the command from the config file, replacing the string variables with the apropriate ones, but it doesn't seem to work. I think it's possible, but I need a few pointers. Any ideas?