Start and shutdown Macs via Config Profile -> Energy Saver

Philibb
New Contributor III

Hello,

i would like to shutdown and start my MACs everyday with the config Profile Settings -> Energy Saver -> Schedule

It works fine when i´m logged into the computer. After 10 minutes the Mac will automatically shutdown.

But if no one is logged into the computer, nothing happens.
I get this message in the console.app a3ecb60530f64e0b84e8725f6e95a4e9

I´m working with JSS Version 9.65
My Macs are running with Yosemite 10.10.3

19 REPLIES 19

millersc
Valued Contributor

Just FYI for those coming across this same problem now with 10.10.x.

https://support.apple.com/kb/PH18583

Appears Apple has changed the way shutdown is now handled in 10.10.

Aziz
Valued Contributor

@Philibb @millersc

This kinda sucks. I've been testing this and it's super inconsistent. For starter, it rarely works when the computer is on the login window.

millersc
Valued Contributor

@Abdiaziz

This does not work when on the login window. It's a change Apple did and it's documented by the KB I posted.

Your Mac must be awake and you must be logged in for it to shut down at the scheduled time. If you are not logged in or your Mac is in sleep, it won’t shut down.

It stinks and we need to find a work around as I know teachers will not be shutting down their workstations and its too much energy wasted. They also seem to have figured out that if they leave an unsaved document open, say Word, it will not force the shutdown schedule. I'm thinking of working a script to find what's up and kill -9 it and do a shut down command. If I get that chance, I'll be sure to share!

Cheers-
Steve

Aziz
Valued Contributor

@millersc

I'm in the same boat. Teachers rarely shut down their machines and lab computers never get powered down.

I'm hoping Apple fixes this.

nessts
Valued Contributor II

I would think you guys could run a launch daemon that does shutdown -h now
at whatever time of day you want and it will shutdown the computer.

millersc
Valued Contributor

@Abdiaziz

I think it was intentional by Apple, that's why they created the KB article. SMH

@nessts I agree. It's on my ToDo list

Aziz
Valued Contributor

@nessts

That would work for some of our computers, but I need the lab computers to be on before classes begin.

@millersc

Agreed.

Look
Valued Contributor III

@Abdiaziz In a lab environment you could just have a script that ran a pmset command to schedule wake/power on. You could also use it for shutdowns as well if you wanted.
It's what I have been using to wake labs up in the middle of the night for updates.
Something like this should wake or power on every weekday at 6am.

pmset repeat wakeorpoweron MTWRF 6:00:00

It looks like it uses R for Thursday and U for Sunday, but man pmset has plenty of examples.

Aziz
Valued Contributor

@Look

I'll be using either pmset or shutdown -h now, both work just fine. Then I'll use a config profile to start them back up.

Nix4Life
Valued Contributor

@Abdiaziz

I'm using a start up config in labs successfully and shutdown -h now as part of an update Launch Agent which I may convert to a profile. so your plan will most definitely work

LS

Aziz
Valued Contributor

I was using a JSS policy to shutdown the machines (Policy - do not run between 5 AM - 10:30 PM).

I would like to move away from that. I'm currently in the process of making an automator .app that quits all applications, then shuts down. That is called upon by a launch agent everyday at 11 PM.

Can you guys share your agents/scripts? Mine is getting pretty sloppy.

Edit:

Can a launch agent run at the login window?

mm2270
Legendary Contributor III
Can a launch agent run at the login window?

Nope. LaunchAgents only run when someone is logged in. LaunchDaemon's can run at any time, but you run into issues performing actions as the logged in user when using a Daemon.

KebsKebs
New Contributor II

This is so confusing.

Apple's Article: https://support.apple.com/en-au/HT201988 states the following.

"Your computer must be awake at the time that it's scheduled to shut down, and remain awake for at least 10 minutes past the scheduled time, in order for it to shut down on its own. If your computer is sleeping at this time it will continue sleeping instead of shutting down. If you've set your computer to go to sleep after less than 15 minutes of inactivity, the computer may go back to sleep before it shuts down."

I've tested this, with a policy to wake up a 10.10.4 mac a minute before a scheduled shutdown, but it will not work unless a user is logged in.

Aziz
Valued Contributor

@kevincnow Take a look at this KB for Yosemite

https://support.apple.com/kb/PH18583?locale=en_US&viewlocale=en_US

Here's a launch daemon that shutdowns the machine at 11 PM, I use a config profile to power them back on.

Package as a .pkg and deploy

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
<string>com.org.shutdown</string>
<key>UserName</key>
<string>root</string>
<key>Program</key>
<string>/sbin/shutdown</string>
<key>ProgramArguments</key>
<array>
    <string>/sbin/shutdown</string>
    <string>-h</string>
    <string>now</string>
</array>
<key>StartCalendarInterval</key>
<dict>
    <key>Hour</key>
    <integer>23</integer>
    <key>Minute</key>
    <integer>00</integer>
</dict>
</dict>
</plist>

Post flight (After script)

#!/bin/bash
chown root "/Library/LaunchDaemons/com.org.shutdown.plist"
chmod 644 "/Library/LaunchDaemons/com.org.shutdown.plist"
launchctl load -w "/Library/LaunchDaemons/com.org.shutdown.plist"

Feel free to suggest any changes to this.

KebsKebs
New Contributor II

Thanks for that, I'll try it out.

What I mean is that. I have made a config profile to set schedule to wake the Mac. That part works. It's just scheduling the "shutdown"

wouldn't it be easier to send a "sudo shutdown -h now" script? via policy at a specified time?

Aziz
Valued Contributor

@kevincnow

As @millersc posted above, this is from Apple's KB article

Your Mac must be awake and you must be logged in for it to shut down at the scheduled time. If you are not logged in or your Mac is in sleep, it won’t shut down.

Link: https://support.apple.com/kb/PH18583?locale=en_US&viewlocale=en_US

Nix4Life
Valued Contributor

@mm2270 Thanks for the correction.

@kevincnow I have this working in that i have the machine check for updates via munki ( that's someone logged in) then the last line is shutdown -h now, works fine, perhaps you could do something similar or setup a script to check if a user is logged in, then run the shutdown..must admit I did not see that Apple KB, I just got lucky with this one =)

LS

Nix4Life
Valued Contributor

whoops sorry double post

@Abdiaziz 's config profile is even better!! since that is the future

KebsKebs
New Contributor II

@Abdiaziz and @LSinNY , Sorry, I have forgotten to mention I have "caffeinate -u -t 1" to wake the machine up first, then sudo shutdown -h now, That seems to work.

#!/bin/sh

#wake mac up
caffeinate -u -t 1

sleep 1

#Shutdown mac
sudo shutdown -h now

I can schedule this at certain times, add groups if need be.