Scheduled Restart

Araneta
New Contributor III

Hi All,

Here's my plist for a scheduled restart:
ee790a001b3c43e6804086e1aaabb699

When I loaded this to one of my test machine it went on a restart loop. I want my kiosk machines to restart everyday on a specific time. Do I need to put in the Weekday key? How can I achieve this?

Thank you
Erwin

2 ACCEPTED SOLUTIONS

Aziz
Valued Contributor

Something like this should work ( This restarts it at 10 PM, I also haven't tested this).

*Can you edit your script so it looks better, it's pretty cluttered and hard to look at right now

<?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>-r</string>
    <string>now</string>
</array>
<key>StartCalendarInterval</key>
<dict>
    <key>Hour</key>
    <integer>22</integer>
    <key>Minute</key>
    <integer>00</integer>
</dict>
</dict>
</plist>

View solution in original post

Aziz
Valued Contributor

@Araneta

You're welcome! A heads up, a restart will be needed to start the daemon.

This will work as well

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

View solution in original post

9 REPLIES 9

Aziz
Valued Contributor

Something like this should work ( This restarts it at 10 PM, I also haven't tested this).

*Can you edit your script so it looks better, it's pretty cluttered and hard to look at right now

<?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>-r</string>
    <string>now</string>
</array>
<key>StartCalendarInterval</key>
<dict>
    <key>Hour</key>
    <integer>22</integer>
    <key>Minute</key>
    <integer>00</integer>
</dict>
</dict>
</plist>

Araneta
New Contributor III

Thanks @Abdiaziz ! :) Will try this now and give you an update.

Aziz
Valued Contributor

@Araneta No problem! Looking at your script, it restarts at 1:35 PM (using the 24 hour format). Are you sure you want it to restart during the day?

01:35 = 1:35 AM

Araneta
New Contributor III

Yup, I'm just testing the script with that time :) (NZ time) I'll change it once I got it working properly.

Araneta
New Contributor III

Here's the updated script, tested it and it ran perfectly :) Thanks @Abdiaziz. So I don't need to include RunAtLoad?

echo "<?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>-r</string>
    <string>now</string>
</array>
<key>StartCalendarInterval</key>
<dict>
    <key>Hour</key>
    <integer>14</integer>
    <key>Minute</key>
    <integer>35</integer>
</dict>
</dict>
</plist>" > /Library/LaunchDaemons/com.company.restart.plist

Aziz
Valued Contributor

I don't, I put the .plist in /Library/LaunchDaemons. Give that a try @Araneta

Araneta
New Contributor III

Yup, it is already saved on that path :)
Thank you so much again @Abdiaziz . I can sleep soundly tonight. :)

Aziz
Valued Contributor

@Araneta

You're welcome! A heads up, a restart will be needed to start the daemon.

This will work as well

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

Araneta
New Contributor III

Did those too as well :)