Auto-Start Programs at Boot Using Crontab with Shell Access

If you have custom code on a groov EPIC that you want to run automatically every time the system boots or reboots, consider using the crontab tool to auto-start it for you.

You can view existing cron jobs with crontab -l , and make changes using the crontab -e command, which will open the crontab file with the text editor vi.

If you’re unfamiliar with vi you should know that it launches in “command mode”, you’ll need to press the i key to enter “insert mode”, make any changes to the file, and then press Esc to go back to command mode. From there you can type :x to save and close the editor, or :q! to force quit without saving.

To add a new cron job that will start at boot, put @reboot in front of your command, and end with an ampersand (&) to run it in the background. Make sure that you include the full path to any programs or files you reference. For example, I put a simple Python script in the unsecured file area, which has the path /home/dev/unsecured, so I added the following line to my crontab to make it run at boot:

@reboot python /home/dev/unsecured/script.py &

Using i to start inserting new text, then Esc and finally :x to save and quit. Once it’s added, double check it with crontab -l and then reboot through groov Manage to test it.

If you start a process in the background that you want to end later, you can use htop or pgrep to find the process ID (PID) and kill $PID to kill the process. For example, I found my Python PID with the command pgrep -f script.py which returned 3310, so a simple kill 3310 stopped it running.

Happy coding!

2 Likes

Is there any other way?

The only other reasonable alternative to starting programs at boot time is systemd, but as near as I can tell, Opto chose not to support it.

What are you trying to run at boot?
What privileges do you need?

We actually have two programs.

First, we have written a program that allows us to send and receive numeric tables to/from an ARCNET of older Opto controllers.

We also have a program that allows a legacy app to communicate with the new groov using the very obsolete “HostWords” interface.

Both of these programs create server sockets.

What are your concerns about using crontab?
Just trying to understand what you are doing and why crontab won’t work for you.