Scripts for Shell and Startup Management
Scripts for Shell and Startup Management
When a shell script runs via crontab, it typically stops after the next reboot unless configured otherwise. You can keep it active by adjusting the crontab settings or using a persistent process manager. This avoids the need to restart manually, similar to keeping a Java app running in a GUI.
I've never tried, but can't you just add it to the start up list? If for some messed up reason you can't just make a simple java script that starts it on start?
I'm not sure for cron, but as @Nater said theres more systematic ways to execute scripts at start up. But, assuming the cron job works the same as just adding the script to the "start up list" then it will only run once per boot. It will run once and end(unless you have a loop or restart or whatever) and will then run again upon restart.
Ubuntu 16.04 LTS and CentOS 7 both support systemd. In this case, the service file is located at "/lib/systemd/system/myscript.service". The unit configuration includes a description, targets, user permissions, execution command, and installation settings. To activate the service at startup, use systemctl enable myscript.service. After enabling, start it with systemctl start myscript.service and verify its status with systemctl status myscript.service. For more details, refer to the Arch Linux Wiki, which provides similar information for Ubuntu and CentOS.
For running scripts at startup, cron is a good option. Your application will remain active until the system restarts or you reboot it. A better approach is creating an init.d script to start your app at boot and halt it before shutdown. You can find more details here, which might be useful.
It's possible this way, but a systemd service would be more effective. A better approach too.