#!/bin/bash

# A rather simple bash script for toggeling any service daemon

# using start-stop-daemon.

# The first argument should be the name of the service to be started.

#if no service was passed exit

if [ [ -z "$1" ] ] ; then

echo "You did not pass a service to toggle" 1 >& 2

exit 2

fi

#execute only as root

if [ [ " $(whoami) " ! = "root" ] ] ; then

echo "Your are not root!" 1 >& 2

exit 2

fi

#the service to be started

stserv = "$1"

#check if the pid file of the service exists

if [ [ ! -e "/var/run/ $stserv .pid" ] ] ; then

#do notexit with error status 2 as the process can be found by name

echo "The PID file of the process does not exist" 1 >& 2

fi

#if the prozess is running

if start-stop-daemon \

--status \

--pidfile "/var/run/ $stserv .pid" \

--name " $stserv "

then

#stop it

if service " $stserv " stop ; then

exit 0

else

echo "Failed to stop $stserv " 1 >& 2

exit 1

else

#else start the process

if service " $stserv " start ; then

exit 0

else

echo "Failed to start $stserv " 1 >& 2

exit 1