When we are running MacBook as a server we need to disable sleep for the MacBook. Otherwise it will not running our pipelines until we will not login into the server via ssh.
Normally we log into our server like this
ssh username@server-name
Later we can check the status of power settings
pmset -g
## output
System-wide power settings:
SleepDisabled 1
Currently in use:
standby 0
Sleep On Power Button 1
hibernatefile /var/vm/sleepimage
powernap 1
networkoversleep 1
disksleep 0
sleep 0 (sleep prevented by powerd)
hibernatemode 3
ttyskeepawake 1
displaysleep 0
tcpkeepalive 1
lowpowermode 0
womp 1
We can enable or disable sleep like this
sudo pmset -a disablesleep 1 ## mac will always awake
pmset -a disablesleep 0 ## mac will sleep when we don't use that
First of all let's create two files with scripts
## file path
/usr/local/bin/disable_sleep.sh
## content
sudo /usr/bin/pmset -a disablesleep 1
## file path
/usr/local/bin/enable_sleep.sh
## content
sudo /usr/bin/pmset -a disablesleep 0
Make both executable
sudo chmod +x /usr/local/bin/disable_sleep.sh
sudo chmod +x /usr/local/bin/enable_sleep.sh
Create launchd Plists
<?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.user.disable_sleep</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/disable_sleep.sh</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>7</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
And for enable sleep
<?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.user.enable_sleep</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/enable_sleep.sh</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>20</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Make sure both have correct permissions:
sudo chown root:wheel /Library/LaunchDaemons/com.user.*.plist
sudo chmod 644 /Library/LaunchDaemons/com.user.*.plist
Launch them
sudo launchctl load /Library/LaunchDaemons/com.user.disable_sleep.plist
sudo launchctl load /Library/LaunchDaemons/com.user.enable_sleep.plist
Check if it’s loaded
launchctl list | grep com.user.enable_sleep
Unload it (stop scheduling it)
launchctl unload /Library/LaunchDaemons/com.user.enable_sleep.plist
The schedule for server is set up 🥳