Starting everything up at boot

Please note that this information is no longer up to date. The content of this site has moved to a new domain DIYMacServer.com which is kept up to date. Apologies for the inconvienince.

We’ve got everything compiled and configured to its time to try to start everything up and to test if it’s working properly. And last but not least is how can you have everything start-up automatically after a reboot.

As a recent switcher I haven’t got the hang of how things work on a very low level in OSX. It’s all a bit different then just using Linux or BSD and to add some more confusion Apple has changed the way daemons are started in 10.4. In 10.3 there where the Startupitems, but in 10.4 Apple starts using Launchdeamons. I’m sticking to the last one as my server will be running on OSX 10.4 Tiger.

Apache
This is one of the easy ones, at least if you used the package from Server Logistics. You should have an Apache2 item in your ‘System Preferences’ panel. With this tool you can start and stop the web server.

apache preference pane

It also has a check-box that states ‘Start Apache 2 At Boot’, mark it checked and your done.

MySQL
MySQL works the same as Apache, if you have chosen the package from Server Logistics. There will be a MySQL item in your ‘System Preferences’ panel. With this tool you can start and stop the database server.

mysql preference pane

It also has a check-box that states ‘Start MySQL At Boot’, mark it checked and your done.

There where some issues for me, as the starting of daemons is quite different in Mac OSX then standard Linux or FreeBSD where you just add a script to the /etc/init.d directory. I’ve written below what I’ve been able to get to work, it might not be the most elegant solution and it might change in the future.

Courier Auth daemon
To have the Courier Authentication daemon to start at a boot you’l have to do the following as a root using the Terminal:

Create a directory CourierAuth in the directory /System/Library/StartupItems
The easy next step is to copy the contents of the Apache startupitem to your new directory using:

cp /System/Library/StartupItems/Apache/* /System/Library/StartupItems/CourierAuth

Then rename the Apache shell script to CourierAuth using:

mv /System/Library/StartupItems/CourierAuth/Apache /System/Library/StartupItems/CourierAuth/CourierAuth

Next you need to edit the renamed file /System/Library/StartupItems/CourierAuth/CourierAuth and have it look like:

#!/bin/sh
##
# Courier Authentication mailserver
##
. /etc/rc.common
StartService ()
{
  if [ "${CAUTHSERVER:=-NO-}" = "-YES-" ]; then
    echo "Starting Courier Auth server"
    /usr/local/sbin/authdaemond start
  fi
}

StopService ()
{
  echo "Stopping Courier Auth server"
  /usr/local/sbin/authdaemond stop
}

RestartService ()
{
  if [ "${CAUTHSERVER:=-NO-}" = "-YES-" ]; then
    echo "Restarting Courier Auth server"
    StopService
    StartService
  else
    StopService
  fi
}

RunService "$1"

The other file to edit in this directory is StartupParameters.plist, have it look like:

{
  Description = "Courier Auth server";
  Provides = ("Authentication Server");
  Uses = ("Disks", "NFS");
}

The last thing to do is to add the following line to the /etc/hostconfig file:

CAUTHSERVER=-YES-

You’re done for this item, on to the next…

Courier IMAP daemon
The IMAP daemon is configured the same as the authentication daemon, the difference is in the details.

Create a directory CourierIMAP in the directory /System/Library/StartupItems
The easy next step is to copy the contents of the Apache startupitem to your new directory using:

cp /System/Library/StartupItems/Apache/* /System/Library/StartupItems/CourierIMAP

Then rename the Apache shell script to CourierIMAP using:

mv /System/Library/StartupItems/CourierIMAP/Apache /System/Library/StartupItems/CourierIMAP/CourierIMAP

Next you need to edit the renamed file /System/Library/StartupItems/CourierIMAP/CourierIMAP and have it look like:

#!/bin/sh
##
# Courier IMAP server
##
. /etc/rc.common
StartService ()
{
  if [ "${IMAPSERVER:=-NO-}" = "-YES-" ]; then
    echo "Starting Courier IMAP server"
    /usr/local/libexec/imapd.rc start
  fi
}

StopService ()
{
  echo "Stopping Courier IMAP server"
  /usr/local/libexec/imapd.rc stop
}

RestartService ()
{
  if [ "${IMAPSERVER:=-NO-}" = "-YES-" ]; then
    echo "Restarting Courier IMAP server"
    StopService
    StartService
  else
    StopService
  fi
}

RunService "$1"

The other file to edit in this directory is StartupParameters.plist, have it look like:

{
  Description = "Courier IMAP server";
  Provides = ("IMAP Server");
  Uses = ("Disks", "NFS");
}

The last thing to do is to add the following line to the /etc/hostconfig file:

IMAPSERVER=-YES-

Note: If you configured the IMAP server to use SSL and/or TLS you need to replace imapd.rc in StartupItems script with imapd-ssl.rc because the SSL option requires a different program to startup.

You’re done for this item, on to the last…

Postfix
The Postfix daemon is configured the same as the authentication and IMAP daemon, the difference is in the details.

Create a directory Postfix in the directory /System/Library/StartupItems
The easy next step is to copy the contents of the Apache startupitem to your new directory using:

cp /System/Library/StartupItems/Apache/* /System/Library/StartupItems/Postfix

Then rename the Apache shell script to Postfix using:

mv /System/Library/StartupItems/Postfix/Apache /System/Library/StartupItems/Postfix/Postfix

Next you need to edit the renamed file /System/Library/StartupItems/Postfix/Postfix and have it look like:

#!/bin/sh
##
# Postfix mail server
##
. /etc/rc.common
StartService ()
{
  if [ "${MAILSERVER:=-NO-}" = "-YES-" ]; then
    echo "Starting Postfix mail server"
    postfix start
  fi
}

StopService ()
{
  echo "Stopping Postfix mail server"
  postfix stop
}

RestartService ()
{
  if [ "${MAILSERVER:=-NO-}" = "-YES-" ]; then
    echo "Restarting Postfix mail IMAP server"
    postfix reload
  else
    StopService
  fi
}

RunService "$1"

The other file to edit in this directory is StartupParameters.plist, have it look like:

{
  Description = "Postfix Mail server";
  Provides = ("Mail Server");
  Uses = ("Disks", "NFS");
}

The last thing to do is to add the following line to the /etc/hostconfig file:

MAILSERVER=-YES-

You’re done, try a reboot if you dare… to check if it all works.

Next page ->, the end result.

2 Responses to “Starting everything up at boot”

  1. Nate Carroll Says:

    Hi, I’m trying to follow your directions to get a webserver and mailserver running on a mac mini. I don’t think my startupitems are running at startup though, and I’m having trouble getting the mail aspect to work.

    From the terminal, if i try to manually run one of the startup items scripts as root, i get:

    root# /System/Library/StartupItems/CourierAuth/CourierAuth
    /System/Library/StartupItems/CourierAuth/CourierAuth: line 8: syntax error near unexpected token `then’
    /System/Library/StartupItems/CourierAuth/CourierAuth: line 8: `? if [ "${CAUTHSERVER:=-NO-}" = "-YES-" ]; then’

    —–
    I get the same error when trying to run the CourierIMAP startup item from the command line. I have copied and pasted the text into these startup scripts but is there a simple syntax error i might have introduced? Thanks for the help! -Nate

  2. Nate Carroll Says:

    Oops, I should point out that the Apache2 and MySQL startup items are working correctly- it just seems to be the ones in /System/Library/StartupItems, and they all seem to have the correct permissions and ownership.