How to create a scheduled reboot script?

I'm running a unifi accesspoint with OpenWrt. I want to create a cronjob the reboots the device on 1st of every month.

I tried:
$ crontab -l
$ 50 16 23 * * /sbin/reboot

The accesspoint rebooted properly, BUT after that the crontab job is lost.

Now in your docs I read about watchcat. Is this the better solution for periodic reboots?
If yes, how can I configure it properly for a monthly reboot after executing the opkg install watchcat from docs?


crontab should work ok for you.

You might read this:

I guess that you are looking for something like this:
30 4 1 * * sleep 70 && touch /etc/banner && reboot
(reboot at 04:30 on the 1st of every month)


@hnyman has given you good information about how to do this.

I'd like to ask why you're interested implementing a reboot script. OpenWrt is generally very stable and should not need to be rebooted very frequently at all (typically only needing reboots when doing a sysupgrade, installing certain packages, or making major configuration changes). If you are running into specific problems, you're better off trying to solve those problems than simply rebooting (which just masks the issue). If it is 'just because' you'd like to reboot every month, consider that it isn't usually necessary and often creates more headaches than it is worth, especially if you mess up and get a reboot-loop going).


But how can I prevent crontab loss after reboot? Because in fact the crontab file is empty after the scheduled reboot.

Should not happens... /etc/crontabs/root file persist after reboots

1 Like

Unfortunately all files under /etc/crontabs/ or /etc/persistent/ are gone after a reboot. Do you know why? Is there any other persistent path? Or is there anything special I have to take into account creating the files?

  1. Which OpenWrt version have you installed on which device?
  2. Please post the output of
    df -h

It's a unifi ap ac lite, if that helps.

$ cat /etc/*-release
VERSION="17.01.6, Reboot"
ID_LIKE="lede openwrt"
PRETTY_NAME="LEDE Reboot 17.01.6"
LEDE_TAINTS="no-all mklibs busybox"
LEDE_RELEASE="LEDE Reboot 17.01.6 r3979-2252731af4"

$ mount
rootfs on / type rootfs (rw)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
pstore on /sys/fs/pstore type pstore (rw,relatime)
tmpfs on /dev type tmpfs (rw,nosuid,relatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,mode=600)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)

$ df -h
Filesystem                Size      Used Available Use% Mounted on
tmpfs                    61.3M    344.0K     61.0M   1% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev

No wonder your settings are gone, you are running on tmpfs.
Any reason why you are still using 17.01.6 instead of 19.07.2?
Which OpenWrt image exactly have you flashed (please provide link)?

I'm just running the default openwrt that was shipped with my access point "unifi ap ac lite".
I don't know if I could simply upgrade openwrt within? Especially as then my management interface from ubiquiti might not work anymore?

Any chance I could add a cronjob outside tmpfs?

Yes, if you properly manage to activate the actual flash. Right now you only store your settings on ramdisk, so everything gets wiped at every reboot.

You should upgrade to a current version. Either 18.06.8 or 19.07.2.

Download this to your PC and use LuCI to sysupgrade.

1 Like

Ok, but I will probably lose unifi management interface compatibility then, won't?

How could I "manage to activate the actual flash"?

but if you use something Unifi OEM specific in their OEM firmware, then you better ask help at their forums, as your things have nothing to do with the proper OpenWrt

This is not a standard LEDE/OpenWrt release -- it is highly customized by Ubiquiti. Just as a reference point, the Unifi AP's are access points only based on their firmware -- they are not setup as routers (a default OpenWrt/LEDE installation sets up the device as a router). Assuming that you are indeed using the Unifi Controller environment, I would highly recommend against messing with the base OS because it may produce unpredictable/unstable results.

Yup... the Unifi Contoller only works with the Unifi firmware. If you install an official release of OpenWrt, you will need to manage the device directly via ssh or http/s (LuCI). OpenWrt is great, but you should evaluate the pros/cons of switching to the official OpenWrt releases -- I personally love the Unifi environment and have specifically opted to stay within this walled garden for my WiFi (I use OpenWrt on other devices).

Meanwhile, I would start with making sure that you are fully up to date with the Unifi Controller and firmware(stable versions 5.12.35 and 4.0.80 respectively as of March 18, 2020).

Then, ask yourself the question I had asked earlier about why you want to do this (you never did answer this). Are you experiencing a specific issue? Most of the time, the Unifi firmware is solid... I have 2x AC-PRO devices that have uptime of 65 days (the last time they were rebooted was for a firmware update). You really shouldn't need to restart these things all that often, if ever, aside from certain major configuration changes and/or firmware updates (this is true for both the Unifi specific firmware and OpenWrt), so a reboot script should not be necessary under normal circumstances.

EDIT: I would not recommend changing from Unifi to official OpenWrt purely for the ability to schedule reboots, but don't let that stop you if you see other benefits. That said, if you are indeed experiencing issues that require reboots and plan to stick with Unifi, as @hnyman said, head over to the UI community forums and ask how to resolve them there.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.