New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
cronjob and screen
Hello,
I'm trying to create a restart script for my CS:S server, so I have a file called restart.sh which contains a part which kills the server (its running over screen) and a part which should start the server again. My script works great when I run it on my own, but with crontab it doesn't work. I already checked google and I read that I should use the -dmS tag for cronjob and screen, but it doesn't work either. I use this line to start the server again:
screen -dmS $SERVER ./srcds_run $PARAMS $PARAMS2
But the CS:S server doesn't start with cronjob. Can anybody help?
thanks
Comments
can you gice us your cron command?
Sure
30 * * * * bash /home/css/css_server/restart.sh
Is it possible that I should give execute rights to others? Currently the rights are: -rwxr--r--
re you editing with crontab -e (or -u) or directly to /etc/crontab ?
I do it with crontab -e
Have you tried restarting the cron service? Had issues like this before.
in what user?
in css user
I had this problem with a minecraft server as well, but I can't remember how I fixed it.
Often, when something works at the command line but fails in a cron job it's because of the path environment.
Try providing the full path to screen, e.g., /usr/bin/screen
which screen
will tell you where it is.so I should use
/usr/bin/screen -dmS $SERVER ./srcds_run $PARAMS $PARAMS2
instead ofscreen -dmS $SERVER ./srcds_run $PARAMS $PARAMS2
?Yes, if you screen binary is indeed at /usr/bin/screen
Also, ./srcds_run is a relative path which may be an issue for cron. Try substituting an absolute path like /full/path/to/srcds_run
Well the restart.sh is located in the folder where the srcds_run is and cronjob only starts the restart.sh
With this comman
screen -dmS $SERVER ./home/css/css_server/srcds_run $PARAMS $PARAMS2
it doesn't start anymore, even when I start the restart.sh myself.Remove that leading dot.
Tip: use tmux instead of screen. It's a superior, smarter (terms and keybindings that make sense), actively developed alternative.
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-tmux-on-ubuntu-12-10--2
You should not need to restart your server everyday, if you do so then you have an issue with a plugin or aren't changing your map on a frequent enough basis.
Mun
what @sleddog says
Thanks that worked
I had a similar cronjob to run when I used to host an Electrum node. I wrote a post on my blog when I found what was wrong (dumb syntax errors) - have look here, it might help you.