Welcome to the navigation

Et culpa in incididunt sint commodo quis non adipisicing eu minim ut sunt nostrud ipsum sit amet, dolor magna pariatur, sed laboris aute deserunt ex. Fugiat in in proident, esse non sed aliquip lorem consequat, cupidatat elit, minim ullamco quis qui ipsum laboris commodo magna pariatur, nostrud amet, aute sunt

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!