Best way to setup auto-restart on a nightly or certain day basis

jamest
New Contributor

Best way to setup auto-restart on a nightly or certain day basis. I want to do it without installing a package to force the restart

18 REPLIES 18

roiegat
Contributor III

You could create a policy that just runs the command "sudo shutdown -r now" and tell it to run daily and set the operating hour on the client side limitations. Although Capser might have issues with this since it might not register that the policy actually ran.

Another options is to use the reboot function in the policy and tell it to reboot immedialtly. This way at least the policy will register as finished before it reboots.

rtrouton
Release Candidate Programs Tester

You can use pmset to schedule a restart. I have a post showing how to do that available via the link below:

https://derflounder.wordpress.com/2016/02/29/using-pmset-on-os-x-to-schedule-restarting-your-mac/

roiegat
Contributor III

Although it should be worth noting that if you have any type of full disk encryption like FileVault, you might not be able to reboot autonomasly without using something like the authenticated restart feature. So be mindful of that.

jduvalmtb
Contributor

You can also use a configuration profile to turn devices off & on.
2784b3cbdce64ad9b359942a6622313b

jakeah18
New Contributor III

there is no "Energy Saver" payload for config profiles in Jamf Pro. Nor do I see any other payload that could facilitate a reboot

CapU
Contributor III

I also use a configuration profile to turn my machines on in a lab, then shut them down in the evening.

stevewood
Honored Contributor II
Honored Contributor II

Using a config profile or pmset to start/shutdown a machine works great, if the user did not leave a document open that needs saving. The only way (that I know of) to get around that is to force the shutdown as @roiegat mentioned.

For a restart:

shutdown -r now

Or for a shutdown:

shutdown -h now

Simply placing that in the Execute Command box of a policy and then setting the policy to execute on whatever schedule you want, should restart the machine.

I use a LaunchDaemon with a local script (issuing the same command) to do this on our lobby computer. That way I can schedule with some accuracy when the shutdown will happen.

apizz
Valued Contributor

I would personally steer away from the shutdown -r/h options. You don't get reporting that it completed or failed, that is unless you have an extension attribute that checks the last restart date & time and a policy set to run at startup which updates inventory.

If you're running 9.82 (and I think 9.81 too?) just create a policy with only the Restart payload enabled. Set your timeframe which to run on your clients and the frequency you want it to run.

2aad45b558af421abd6cdcf750a4c305

This way it's reported and you can choose a timeframe when the computers are available to restart.

apizz
Valued Contributor

@jduvalmtb 's method will forcibly shutdown if a user is logged in and using the computer. The method above allows you to set options for if someone is logged in or not.

Morningside
Contributor II

@aporlebeke What I don't understand is how to use the policy method to reboot the machines nightly. If I create a policy with only the restart payload configured, as pictured above, how do I configure the Trigger and the Frequency to have a nightly reboot as say, 2:00 AM?

apizz
Valued Contributor

@Morningside So the smart group I have configured is what pops the lab machines into the policy scope based on an extension attribute which reads the date & time of the last reboot. I have this set to more than 6 days ago to achieve the desired weekly result.

16573472598c4cf58b2150f88e589248

The policy itself, which is set to trigger once a week, I have client-side limitations setup such that it only runs on the day I want and between the hours I want, in this case Friday mornings between 1 & 5:59 am (this after our Jamf Pro server completes its daily database backup). So even if lab machines are in the group, the policy doesn't run until the desired day & timeframe.

48d9dd9d6a5c4fd6af670c9dfa181ed6

With the once a week trigger, this avoids the policy from running again, as we don't have the machines update inventory on startup in order to collect the new last reboot date.

Hope that makes sense.

Morningside
Contributor II

@aporlebeke Thanks for that! I have set mine up for my lab iMacs as shown above and could not be happier. I appreciate the help!

geebee
New Contributor II

@apizz

I've dug around and can't figure out how you got that custom operator, "more than x days ago". Got any tips?
Were on Jamf v.10.25.

TIA!!!

apizz
Valued Contributor

@geebee your EA has to be configured as a 'Date'

9c4dea5715574786aa6f9a87738a2e13

JAMFInfra
New Contributor

3bc0201a9abf40ad9e49c061859783d6

45afcc0c0ae1442dbbe312ef80219c64
Hello,

Trying to use the script referenced here have created a Extension Attribute as shown in the image below, and have the policy setup as shown in the second image the policy runs successfully but never puts the key into the computer extension attribute record

Thanks for your help in advance
b33f24916c094a73806690d5cefa1389

apizz
Valued Contributor

@JAMFInfra You have a policy running a script, which isn't correct. You need to put the script for returning last boot time in the EA itself by changing the input type from "Text Field" to "Script".

apizz
Valued Contributor

There's nothing inherent about running a script as part of policy that will return data to an extension attribute

JAMFInfra
New Contributor

Thanks so much the EA is working now!