To summarize my understanding so far:
I use cron to make 2 things - 1. a reboot command every 24 hours at a given point in time @daily - 2. start the startserver.sh at boot
@daily is not run at boot. It's run once a day. Off the top of my head I forget what time it runs, probably midnight.
@reboot is run at boot.
I know how to make the first one, but not entirely sure what the command looks like for no.2
Code:
@daily some-commandFurthermore, as i understand.....(I've skimmed the guide provided) i can not make a command that keeps an eye (Is the server running, otherwise start the server), but should be able to make such a command in systemd......??
Is that a correct assumption? (I know right) - and is there a guide that i can use for that problem?
cron will run your command at the specified time but will do no status monitoring and restarting. It'll also happily run it again even if the previous job hasn't finished.
If you need your server to restart after it exits it is possible from cron but you need a shell script wrapper e.g.:
Code:
#!/bin/bashwhile :do start-my-serverdoneIt's hacky, assumes start-my-server is run as a foreground job, and may cause your server to be restarted when you don't want it to be (like during system shutdown).
A better choice, as you've noted, would be to use systemd. That's what Restart= in your .service file is for. Using a systemd service also give finer control over start up timing and dependencies than cron does (cron tries to run your @reboot command as soon after cron it self has started as possible. That's usually before things like teh desktop and networking are available).
Statistics: Posted by thagrol — Fri Apr 11, 2025 4:06 pm