Back to Blog
Server
November 4, 2025
Fahim Hossain

Adding Startup Scripts to Launch Daemon on Mac OS X Sierra 10.12.6

Being new to working on OS X, it has been somewhat confusing to how things work on Mac compared to that on Linux — to be completely honest it has been a painstaking journey while wrapping my head around the differences between the systems.

Being new to working on OS X, it has been somewhat confusing to how things work on Mac compared to that on Linux — to be completely honest it has been a painstaking journey while wrapping my head around the differences between the systems.

I intend to share my experience relating to adding start up shell scripts to the Launch Daemon on OS X Sierra. Any suggestions for a better solution is most welcome.

A good starting point to get to know about Launch Daemon Process — how to configure, troubleshoot and get some examples can be found here.

What is a Daemon

A daemon is a program running in the background without requiring user input.

Task in Hand

  1. Create an shell script file to start mariadb (for simplicity of demo)
  2. Launch the shell script file as soon as the computer boots up (i.e. without requiring the user to login)

Lets Start

Step 1: Create an shell script file using the terminal

Now add in the following code to the file — save and exit. This primarily checks if the mariadb service is enabled or not and then starts the service if it is stopped.

Give the script file execution permission

Step 2: Launch the shell script file as soon as the computer boots up

We now have to add the script file to the Launch Daemon process — which will run the Job as soon as the Mac is booted.

Job Description

The behavior of a daemon/agent is specified in a special XML file called a property list. Depending on where it is stored it will be treated as a daemon or an agent.

Again, just to be clear between the difference between daemon/agents:

The main difference is that an agent is run on behalf of the logged in user while a daemon runs on behalf of the root user or any user you specify with the UserName key.

In Mac OS X, the Launch Daemons are stored inside

folder while the Launch Agents are inside

Now, lets create a property list file(.plist) here as root user. (Please note there are conventions in naming the plist file which is outside the scope of this article)

Configuration of the plist file will vary upon your use case. The list of properties that can be configured is again nicely illustrated under the Configuration section on launchd.info

For easier illustration, please check the following plit file and the inline commets:

Now that we have all the necessary files ready and in place, we need to add the property list file onto the launchctl as follows:

Other notes,

  • To permanently remove the plist to the Launch Daemon
  • Once a script is added onto the Launch Daemon it will auto-start even if the user runs the following command
  • A Gist with the source files is provided here.

That is it!

Do let me know if this works for you! Any suggestion for improvement will be most appreciated.

Running infrastructure like this in production? ARITS does Kubernetes and DevOps platform engineering so your team can ship without babysitting servers.

Have a project you want built right?

Tell us the scope and your deadline. You will get a straight read on what it takes to build, and what it will cost, from a team that has shipped 400+ projects out of Dhaka and London.