Need to make TrueNAS turn off and on at specific times

tech newbie

Dabbler
Joined
Jun 17, 2021
Messages
17
Hi, I have just got my TrueNAS setup running and it is all good. I want to make it turn off over night so that I save energy. Is there a way that I could get my machine to turn off at 11PM? and turn back on at 6AM every morning.
Thanks
 
Last edited by a moderator:
Joined
Jun 2, 2019
Messages
591
Typically it is not recommended to power cycle a NAS daily as it will actually put more power cycles and thermal cycles on your hardware, but if you insist.

1. You can add a cron task to issue the "shutdown -h now" command at the prescribed time
2. To power back up you will need to:
a. Enable WOL in your system BIOS (assuming your NAS NIC supports it)
b. Send magic WOL packets from another client to your NAS.
 

tech newbie

Dabbler
Joined
Jun 17, 2021
Messages
17
Is this correct for the cron task?
 

Attachments

  • Screenshot 2021-09-04 190829.png
    Screenshot 2021-09-04 190829.png
    103.3 KB · Views: 2,132

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
The command should be shutdown -p now. Literally. Do not replace "now" with a time. -p is for ACPI power off which @elvisimprsntr missed.
 
Joined
Jun 2, 2019
Messages
591
Is this correct for the cron task?
Since you scheduled the cron to run at the requisite time, you should use the "now" option. Otherwise, it will take 24 hours before it will actually shutdown.
 
Last edited:

tech newbie

Dabbler
Joined
Jun 17, 2021
Messages
17
Ok, thanks, here is an updated screenshot of the cron job
I will test it soon
 

Attachments

  • Screenshot 2021-09-05 093053.png
    Screenshot 2021-09-05 093053.png
    102.7 KB · Views: 2,378
Joined
Jun 2, 2019
Messages
591
Ok, thanks, here is an updated screenshot of the cron job
I will test it soon
FYI, Since you are running the script daily, you can leave months and days unchecked. The "*" is a wildcard, which means every day/month.
 

tech newbie

Dabbler
Joined
Jun 17, 2021
Messages
17
When I try to run the cron job the nothing happened??
I have attached a screenshot of the cron job
 

Attachments

  • Screenshot 2021-09-06 182110.png
    Screenshot 2021-09-06 182110.png
    97.3 KB · Views: 1,329
Joined
Jun 2, 2019
Messages
591
The "-p" option requires hardware support.

Try

Code:
shutdown -h now
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
-p is equivalent to -h if no ACPI power off is possible. He probably needs to use /sbin/shutdown instead of just shutdown.
 

elorimer

Contributor
Joined
Aug 26, 2019
Messages
194
For turning on at a specific time, you might check in to one of two things.

First, your motherboard may support boot by RTC, which would start up the computer based on the real time clock.

Second, you motherboard may have a setting to boot when power is restored (which is a good idea anyway). Then you could plug it into a wifi power switch that supports a schedule, possibly through Alexa or Google Assistant.

Does WOL work if you used shutdown -hor shutdown -p? Also, could the OP use shutdown -r 420?
 
Last edited:
Joined
Jun 2, 2019
Messages
591
Does WOL work if you used shutdown -hor shutdown -p?
Yes. You just need to send magic WOL packets from another client. I tested by sending WOL packets from another TrueNAS system.

Also, could the OP use shutdown -r 420?
No. That will reboot at the requested time.
 

tech newbie

Dabbler
Joined
Jun 17, 2021
Messages
17
Unfortunately I've tried updating the cron job with /sbin/shutdown but still no luck. I don't know what you mean by WOL packets?
I have attached another screenshot of the cron Job
 

Attachments

  • Screenshot 2021-09-07 113715.png
    Screenshot 2021-09-07 113715.png
    95.9 KB · Views: 1,136
Joined
Jun 2, 2019
Messages
591

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Unfortunately I've tried updating the cron job with /sbin/shutdown but still no luck. I don't know what you mean by WOL packets?
I have attached another screenshot of the cron Job
Why did you remove the user from the screenshot? There is nothing security relevant to that information that could be exploited remotely. The command must be run as root of course.
 

tech newbie

Dabbler
Joined
Jun 17, 2021
Messages
17
The command must be run as root of course.
Thank You! I was not running it as root.
Unfortunately I now get a prompt to "press any key to reboot" on the NAS machine and pressing keys does not do anything. I also have to hard power off to return the machine to a working state.
 

Attachments

  • IMG-0283.jpg
    IMG-0283.jpg
    266.7 KB · Views: 1,933

Arwen

MVP
Joined
May 17, 2014
Messages
3,611
Please use the "-p" option instead of "-h", as been suggested earlier. FreeBSD works slightly different.

As for wake up, some BIOS have an option to start up at a specific time. So check the BIOS options out.
 
Top