Do you want certain applications or scripts to automatically start as soon as your Linux server is powered up? In this blog post, we'll show you how you can accomplish this using "crontabs". This method works regardless of the type of operating system, whether it's Debian, Ubuntu, CentOS, or AlmaLinux.
Manually starting applications or scripts can often be a tedious task, especially if you have a multitude of services that need to be online again after a server restart. Thankfully, Linux provides a solution in the form of "crontabs" that significantly eases this burden.
What is Crontab and How Do I Use It?
Crontab (short for "cron table") is a program used in Unix-based operating systems to execute scheduled tasks (cron jobs). You can use it to start applications automatically after the server starts.
First, you should set your preferred text editor for crontab. In the following example, we're using "nano", an easy-to-use editor that comes pre-installed on most Linux systems. To do this, enter the following command:
export VISUAL=nano; crontab -e
Once you've opened the editor, you can now add a new command for the `@reboot` in the crontab. A typical example might look like this:
@reboot sleep 60 && cd /<DIRECTORY-TO-SCRIPT>/ && bash <YOUR-SCRIPT>.sh
The "@reboot" signals to the system that the following command should be executed at every system startup. The "sleep 60" command ensures the action is only executed 60 seconds after the system boots up, to avoid potential timing issues. Afterwards, "`cd /<DIRECTORY-TO-SCRIPT>/`" changes to the directory where your script resides, and "`bash <YOUR-SCRIPT>.sh`" executes the script.
Here are some examples for popular applications:
Voice servers (TeamSpeak):
@reboot sleep 45 && cd /home/<TEAMSPEAK-DIRECTORY>/ && sudo -u <TEAMSPEAK-USER> bash ts3server_startscript.sh start
Games, Bots, other applications (e.g., Arma3, Minecraft, LinuxGSM-Games, etc.):
@reboot sleep 60 && cd /<DIRECTORY>/ && bash start.sh
We recommend always using a different timer "sleep value" (at least "45") per line. The "sleep" value runs in seconds.
To test whether your configuration is working, simply reboot the server with the "reboot" command and check if your applications start as expected.
Do you have a vServer / root server and would like to have more performance? Then a look at our range of root servers couldn't hurt!
With the discount code "KernelHost-Tutorials" you also receive a 10% discount (permanent) on your tariff!
More details:
Hardware: https://www.kernelhost.com/en/hardware
Datacenter: https://www.kernelhost.com/en/datacenter
DDoS-Protection: https://www.kernelhost.com/en/ddos-protection
PrePaid: https://www.kernelhost.com/en/prepaid
Didn't the instructions help you? You can contact us here via ticket! We're here to help.
© KernelHost.com - Re-posting these instructions on your website is not permitted.