Running Octez at boot on Macs

Octez is the software that runs the Tezos blockchain. It includes the command-line wallet, the node, the DAL node and the baker, amongst other things.
You can currently install Octez on a Mac using Homebrew, but there are plans to deprecate this method. You can build Octez from source and once you’ve done that, you need a reliable way to start and stop the services on boot.
On the Mac, launchd is used to start and stop services. It can be configured with launchctl. There are two main types of launchd service - Launch Daemons and Launch Agents. Launch Daemons are started on boot by the operating system. Launch Agents are started on login for specific users.
We give examples of the Launch Daemon property list configuration files (plists) for the node, DAL node, baker and accuser. These are written in XML.
The plists assume that there is a tezos user on the system with home directory /Users/tezos. You can create this with:
sudo dseditgroup -o create tezos
sudo sysadminctl -addUser tezos -fullName Tezos
sudo dseditgroup -o edit -a tezos -t user tezos
We will need a log directory as well:
sudo mkdir -p /Users/tezos/logs
sudo chown -R tezos:tezos /Users/tezos
You’ll need to configure each service and if you are baking, set up the keys. This needs to be done as the tezos user. For example to configure the node:
sudo su - tezos
octez-node config init --history=rolling --network=mainnet
exit
They also assume that the Octez binaries are installed in /usr/local/bin. You can copy them there, or change the paths in the plists as appropriate.
We will use the bootstrap command to start the service and make sure it runs at boot. We will use the bootout command to stop the service and stop the automatic running at boot.
You can adapt these plists to make Launch Agent plists that run under your own user account. Instead of the services starting on boot, they will start on login. We will show you how to do this for the node.
octez-node
As root, save the file below as /Library/LaunchDaemons/com.tezos.octez-node.service.plist. The command line arguments need to be split across lines in the XML - for example, examine the ProgramArguments section below. The syntax to run the node octez-node run --data-dir /Users/tezos/.tezos-node is split into four strings.
<?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.tezos.octez-node.service</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/octez-node</string>
<string>run</string>
<string>--data-dir</string>
<string>/Users/tezos/.tezos-node</string>
</array>
<key>UserName</key>
<string>tezos</string>
<key>GroupName</key>
<string>tezos</string>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/tezos/logs/octez-node.start.log</string>
<key>StandardOutPath</key>
<string>/Users/tezos/logs/octez-node.start.log</string>
<key>WorkingDirectory</key>
<string>/Users/tezos</string>
</dict>
</plist>
Make sure that it has the correct ownership.
sudo chown root:wheel /Library/LaunchDaemons/com.tezos.octez-node.service.plist
sudo chmod 644 /Library/LaunchDaemons/com.tezos.octez-node.service.plist
Once the node has been configured, you can start it with:
sudo launchctl bootstrap system /Library/LaunchDaemons/com.tezos.octez-node.service.plist
The daemon will launch on boot (as RunAtLoad is set). If you want to use your Mac as a server, you’ll need FileVault disk encryption turned off which has security implications. If you don’t do this, the Mac won’t be able to start unattended.
To stop the node and also stop it from running at boot use:
sudo launchctl bootout system /Library/LaunchDaemons/com.tezos.octez-node.service.plist
It’s also possible to run the service under your own user as a Launch Agent. Note that they will only start automatically when you log in interactively, but this might be the behaviour you want. For octez-node, you can save this plist as ~/Library/LaunchAgents/com.tezos.octez-node.service.plist. Make sure you change the path to octez-node and replace /Users/chris with your home directory.
<?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.tezos.octez-node.service</string>
<key>ProgramArguments</key>
<array>
<string>/Users/chris/bin/octez-node</string>
<string>run</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/chris/Library/Logs/octez-node.start.log</string>
<key>StandardOutPath</key>
<string>/Users/chris/Library/Logs/octez-node.start.log</string>
<key>WorkingDirectory</key>
<string>/Users/chris</string>
</dict>
</plist>
Then to start the service, find your user ID and run launchctl:
$ id -u
501
$ launchctl bootstrap gui/501 ~/Library/LaunchAgents/com.tezos.octez-node.service.plist
octez-dal-node
As root, save the file below as /Library/LaunchDaemons/com.tezos.octez-dal-node.service.plist. Make sure it is owned by root and wheel as per the node above.
<?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.tezos.octez-dal-node.service</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/octez-dal-node</string>
<string>run</string>
<string>--data-dir</string>
<string>/Users/tezos/.tezos-dal-node</string>
</array>
<key>UserName</key>
<string>tezos</string>
<key>GroupName</key>
<string>tezos</string>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/tezos/logs/octez-dal-node.start.log</string>
<key>StandardOutPath</key>
<string>/Users/tezos/logs/octez-dal-node.start.log</string>
<key>WorkingDirectory</key>
<string>/Users/tezos</string>
</dict>
</plist>
If you are running a DAL node on a different machine to your baker, you may also need these program arguments (and firewall protection):
<string>--rpc-addr</string>
<string>0.0.0.0:10732</string>
Once the DAL node is configured, you can start the service with:
$ sudo launchctl bootstrap system /Library/LaunchDaemons/com.tezos.octez-dal-node.service.plist
You can stop the service with:
$ sudo launchctl bootout system /Library/LaunchDaemons/com.tezos.octez-dal-node.service.plist
octez-baker
As root, save the file below as /Library/LaunchDaemons/com.tezos.octez-baker.service.plist.
<?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.tezos.octez-baker.service</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/octez-baker</string>
<string>run</string>
<string>with</string>
<string>local</string>
<string>node</string>
<string>/Users/tezos/.tezos-node</string>
<string>--liquidity-baking-toggle-vote</string>
<string>SETME</string>
<string>--dal-node</string>
<string>http://localhost:10732</string>
</array>
<key>UserName</key>
<string>tezos</string>
<key>GroupName</key>
<string>tezos</string>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/tezos/logs/octez-baker.start.log</string>
<key>StandardOutPath</key>
<string>/Users/tezos/logs/octez-baker.start.log</string>
<key>WorkingDirectory</key>
<string>/Users/tezos</string>
</dict>
</plist>
Change SETME to the appropriate liquidity baking vote. Also, check that the DAL node configuration is correct for your setup. This setup will attempt to bake with all the keys it can find in the wallet. If you have a baking key from another system, be very careful otherwise you will double bake.
You can start the service with:
$ sudo launchctl bootstrap system /Library/LaunchDaemons/com.tezos.octez-baker.service.plist
You can stop the service with:
$ sudo launchctl bootout system /Library/LaunchDaemons/com.tezos.octez-baker.service.plist
octez-accuser
As root, save the file below as /Library/LaunchDaemons/com.tezos.octez-accuser.service.plist.
<?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.tezos.octez-accuser.service</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/octez-accuser</string>
<string>run</string>
</array>
<key>UserName</key>
<string>tezos</string>
<key>GroupName</key>
<string>tezos</string>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/tezos/logs/octez-accuser.start.log</string>
<key>StandardOutPath</key>
<string>/Users/tezos/logs/octez-accuser.start.log</string>
<key>WorkingDirectory</key>
<string>/Users/tezos</string>
</dict>
</plist>
You can start the service with:
$ sudo launchctl bootstrap system /Library/LaunchDaemons/com.tezos.octez-accuser.service.plist
You can stop the service with:
$ sudo launchctl bootout system /Library/LaunchDaemons/com.tezos.octez-accuser.service.plist