Why schedule a reboot?
I wanted to schedule the DSTAR repeater, that I manage, to reboot automatically every Monday morning. The reason for this is that sometimes Pi-Star stops working and/or freezes up. This typically happens every 2 or 3 weeks of uptime without a reboot. My best guess is that due to the log files not being deleted after rotation, that the Pi software gets “clogged up.” I’ve found settings that are supposed to rotate the logs and only keep a certain number of log files, but those do not appear to work, at least not on our setup.
Since these log files are deleted on every reboot of the Pi, the next best idea in my opinion is to schedule a late-night/early-morning reboot once a week.
I used cron to schedule a reboot. I also use cron to schedule automatic linking and unlinking of reflectors. Pi-Star uses a specialized version of cron that adds a “run as user” option.
Find the Expert Cron Editor Tab
- The first step is to log in to your Pi-Star dashboard. This can be accessed by opening a web browser and going to http://pi-star.local/ or http://pi-star/ or the IP address/host name of your Pi-Star repeater or hotspot.
- After logging in to your Pi, click on “Configuration” in the upper right of the page.
- Next in the upper right of the page click on “Expert”, then on the following page in the bottom row of links on the top of the page click on “System Cron.”
Understanding cron
- You will see a text box open with a bunch of seemingly cryptic text. Each line is a cron task that is scheduled to happen at a certain time. It should look similar to this:
- About halfway down the text box you will see the following line:
# m h dom mon dow user command - This line tells us the format of each cron task. The # symbol indicates a comment and tells cron to ignore that line.
The “m” indicates “minutes”, “h” indicates hours, “dom” indicates Day of Month, “mon” indicates month, “dow” indicates Day of Week, “user” indicates the user the the command should run as, and “command” is the command you want to run at the given time/day. Refer to the chart below for options for each position in the line.
m (Minutes) |
Enter the minute you want to run the task at or * for any minute. |
h (Hours) |
Enter the hour you want to run the task at or * for any hour. |
dom (Day of Month) |
Enter the day of the month you want the task to run at or * for any day of the month. Options: 1-31 (date of the month) Example: * = any day of the month Example: 5 = 5th of the Month |
mon (Month) |
Enter the month you want to run a task or * for any month. Options: 1 = January, 2 = February, 12 = December Example: 4 = Run in April Example: 1,6,12 = Run in January, June, & December Example: * = Run any month |
dow (Day of Week) |
Enter the day of the week you want to run the task or * for any day of the week. Options: 0 or 7 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday Example: 0,3 = run on Sunday and Wednesday Example: 7 = run on Sunday Example: * = run any day |
user | Enter the username of the user that you want to run the command. Options: pi-star, root Example: root |
command | Enter the command to run. This can be a script or a single command or multiple commands. Example: reboot Example: pistar-link unlink && pistar-link ref063_c The above example will unlink the repeater and then link to REF063C. |
- Normally when you add a cron task it can be anywhere in the cron file, new lines are typically added at the end. In Pi-Star this works too, except that for some reason a line containing the reboot command should be put in as the first cron task in the list, right below the line we see in step 2 under “UNDERSTANDING CRON”.
- Note that if you add anything to the end of the file that you must maintain the new blank line at the end of the file. If you’re at the end of the last cron line, press the down arrow on your keyboard. If you see the cursor move down to the blank line, you’re all set. If the cursor doesn’t go down, just press “enter” on the keyboard to add a blank line at the end of the file.
How to Schedule a Reboot
- In order to schedule a reboot every Monday at 4:55am, I entered the following line as a cron job.
55 4 * * 1 root reboot >/dev/null 2>&1 - Don’t forget to put it at the top of the cron job list, before the first cron job line, but after the line: # m h dom mon dow user command
- Now we have a job that says, at 4:55AM every/any month, every/any day of the month, on Monday, run the reboot command as the root user, and do not show output.
- The >/dev/null 2>&1 means that whatever text output the command generates won’t be shown or logged. For more info on what this part of the command means, see this forum post on Stack Exchange.
More Info on Cron
https://www.adminschoice.com/crontab-quick-reference
https://www.freeformatter.com/cron-expression-generator-quartz.html
If you use the cron expression generator from Free Formatter, it will not work with Pi-Star, but it will give you the idea of how to write a cron expression. It also lists all the different options and has plenty of great examples of how to use cron.