Welcome to the navigation

Exercitation veniam, fugiat dolor nulla eiusmod aute duis reprehenderit magna ipsum anim occaecat tempor elit, nisi officia ea commodo proident, dolor nostrud est dolore esse. Pariatur, cupidatat aliqua, tempor voluptate proident, quis nisi est commodo elit, veniam, reprehenderit occaecat labore ipsum laboris dolore nulla excepteur velit sunt dolor ullamco minim

Yeah, this will be replaced... But please enjoy the search!

Restart all running services in OS X Server

Categories Tags
In some Linux distributions it's possible to restart all running services by typing
$/sbin/services.sh restart
This guide will help you to create an equivalent command in OS X Server. This should work on pretty much any OS X server version, but I have only tested it in Leopard Server and Snow Leopard Server.

First things first

Start by creating the script, I prefer nano but pretty much any text editor will do
$nano ~/Documents/serviceRestart
Paste this text into the script
# /bin/sh
echo "--- Script start ---"

# Create the array
services=( $(sudo serveradmin list) )

# Make the masterloop
for eachService in ${services[@]}; do

  # Check the status of the current service listed in the array
  tc=$(sudo serveradmin status $eachService | grep -io "RUNNING")

  # If the service is running, then restart it, we wont touch other services
  if [ "$tc" = "RUNNING" ]; then
    echo $i $eachService "(RUNNING)"
    sudo serveradmin stop $eachService && sudo serveradmin start $eachService
  fi

done
echo "--- Script end ---"
# /bin/sh
"--- Script start ---"
dd execute rights to the script
$sudo chmod +x ~/Documents/serviceRestart
And link the script into /usr/bin for easy execution
$sudo ln -s ~/Documents/serviceRestart /usr/bin/

Running the script

Open the terminal and enter
serviceRestart
The sudo command inside the script might ask for your password. This is normal. Good luck!