Friday, April 4, 2008

'service' for the rest of us

so my buddy scott likes the "service" command shipped with redhat. he has ubuntu installed on his computer, but was frustrated with not being able to list what existed in /etc/init.d, in a quick manner. i popped into his box and rewrote the "service" shell script to my own liking, and made it easy for him to use. for your enjoyment, i have posted that script here:


#!/bin/sh
# updated by Matthew Stephen Hartmann (***@***.***)
# 04/04/2008

E_BADARGS=100
E_GOOD_DAY=101

set -e

if [ $# -eq 0 ]
then
echo "Usage: `basename $0` [option] service-name [instruction]"
echo "Use '-h' or '--help', for help"
exit $E_BADARGS
fi

while [ $# -gt 0 ]; do
case "$1" in
-l|--list)
shift
ls /etc/init.d/
exit $E_GOOD_DAY
;;
-s|--service)
shift
/etc/init.d/$1 $2 $3
exit $E_GOOD_DAY
;;
-h|--help)
echo "Usage: `basename $0` [option] service-name [instruction]"
echo ""
echo "-s | --service option executes the instruction"
echo "i.e.: service -s samba restart"
echo ""
echo "-l | --list option lists services available"
echo "i.e.: service -l"
echo ""
exit $E_GOOD_DAY
;;
* )
echo "Usage: `basename $0` [option] service-name [instruction]"
echo "Use '-h' or '--help', for help"
echo "** invalid argument given **"
exit $E_BADARGS
;;
esac
shift
done



needless to say, it makes having to "ls /etc/init.d/" easier; simply type "service -l" and you're done. to run a service you type "service -s samba restart". cheers!