chkconfig for ubuntu or other debian based linux systems



As I’ve mentioned I’ve got an ubuntu based test system. Most of my linux experience has been from a red-hat derivitive-based background and for that, at the command line, you have chkconfig which is a good tool for checking the configuration of services to run at startup. It is a red-hat derivitive thing… However, I found this forum post where someone contributed a “chkconfig” script that does the same thing. I tried it and it’s somewhat slow compared to it’s red-hat derivitive counterpart, but…. it does the job.


This script was posted by jbharrison on the ubuntu forums…. copied here for reference/mirroring/convenience.

#!/bin/bash
#----------------------------------------------------------------
# Title: rc-config
# Author: Joseph Harrison
# Date Created: 12/16/2005
# Date Modified: 12/16/2005
# Purpose: Configure services and run-levels
# Dependencies: grep, sed, update-rc.d
#----------------------------------------------------------------

USAGE="Usage: rc-config [OPTION] [SERVICE ... STATE]n
Information about services and run-levels, configure services and run-levelsn
Sorts entries alphabeticallyn
n
Mandatory arguments to long options are mandatory for short options too.n
-h,ttt Show helpn
-l,ttt List all services and run-levelsn
-ls ,tt List a specific service and run-levelsn
-s
,t Configure servicen
ttt Ex: rc-config -s ssh offn
-t,ttt Terse outputnn"
LISTSVC=0
SETSVC=0
TERSE=0

checkroot(){
if [ $EUID -ne 0 ]
then
echo "you must be root to use this feature"
exit 1
fi
}

checkopts()
{
while getopts "lsth" flag
do
case $flag in
l ) LISTSVC=1;;
s ) SETSVC=1;;
t ) TERSE=1;;
h ) echo -en $USAGE;
exit 1;;
* ) echo -en $USAGE
exit 1;;
esac
done
if [ -z "$1" ]
then
echo -en $USAGE
fi
}

showrc(){
if [ $TERSE -eq 0 ]
then
echo -en "SERVICEtttRUN-LEVELSn"
fi

if [ $SETSVC -eq 0 ]
then
slist=`find /etc/init.d/ -perm -100
| sed "s//etc/init.d///"`
elif [ $SETSVC -eq 1 ]
then
svc=$2
if [ -f "/etc/init.d/$svc" ]
then
slist="$svc"
else
echo "$svc: does not exist"
exit 1
fi
fi

for msvc in $slist
do
sln=18
tsvc=$msvc
while [ ${#tsvc} -lt $sln ]
do
tsvc="$tsvc "
done
echo -en "${tsvc:0:$sln}t"
for level in 0 1 2 3 4 5 6
do
svcs=`ls -1 /etc/rc${level}.d/S*
| sed "s//etc/rc${level}.d/S[0-9]*//"`
state=0
for svc in $svcs
do
if [ "$svc" = "$msvc" ]
then
state=1
continue
fi
done
if [ $state -eq 1 ]
then
echo -en "$level:ont"
else
echo -en "$level:offt"
fi
done
echo
done
}

setsvc(){
svc=$2
state=$3

if [ -z "$svc" ] || [ -z "$state" ]
then
echo -en $USAGE
exit 1
fi

if [ ! -f "/etc/init.d/$svc" ]
then
echo "$svc: does not exist"
exit 1
fi

if [ $state = "on" ]
then
update-rc.d $svc defaults
elif [ $state = "off" ]
then
echo "disabling service: $svc"
/etc/init.d/$svc stop > /dev/null
for link in `find /etc/rc* -type l -name "[S,K][0-9][0-9]$svc"`
do
unlink $link
done
else
echo -en $USAGE
fi
}

main(){
checkopts "$@"
if [ $LISTSVC -eq 1 ]
then
showrc "$@"
elif [ $SETSVC -eq 1 ]
then
checkroot
setsvc "$@"
fi
}

main "$@"

Related Posts

Blog Traffic Exchange Related Posts
  • Linux Market Share Growing Faster than Apple! | Linux adoption rate beats iPhone I had to find a twist like that headline above reading this article. Net Applications does a monthly survey across sites that receive 160 million visitors to gauge the "market share" of operating systems and web browsers. According to the November numbers, Microsoft Windows has no fallen below 90% market......
  • Clamav .90 build problems on Mandrake 10.0 As I've mentioned, there are a few older Mandrake (now Mandriva) systems that I maintain and one of the packages that I'm frequently rebuilding for those systems is clamantivirus. Well, 0.90 came out recently and on an attempted rebuild from the src. rpm that I acquired from ftp.neocat.org, I got......
  • How do I find my IP address This is one that can be handy from time to time, trying to find your ip address. If you're on a lan there aren't too many ways to find your public ip within the operating systems software. However, under Windows if you go to, Start, Run and then type cmd......
Blog Traffic Exchange Related Websites
  • Incorporate Stair-climbing into an Intense Cardio Workout Hmm - spring!¬† Finally the weather is beginning to warm up - take advantage of that by moving some of your workouts outdoors.¬† Especially if you're lucky enough to live near a wooded trail system, combining fresh air and exercise and trees is a great way to get in......
  • Wilson Camp Prattville, Lake Almanor, CA Wilson Camp Pratville is located on: Lake Almanor Phone: 530.259.2267 Average Water Depth: Lake Almanor's levels can vary greatly. Please call ahead for the exact level before you arrive. Marine Stand by Channel: Not at this time, but you can reach the marina by phone. Is there a pumpout station?......
  • Buy Digital Cameras 9 Things to Consider Before Buying Digital Cameras So what are to consider when you things you want to buy a digital cameras? Why you have to think before decide, because¬† you will find so many type and brand of this gadgets in the market. Digital cameras come in many......
en.pdf24.org    Send article as PDF   

Similar Posts


See what happened this day in history from either BBC Wikipedia
Search:
Keywords:
Amazon Logo

Comments are closed.


Switch to our mobile site