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......
  • Linux software raid notes Here are a few other notes on linux software raid. I created a directory called raidinfo to keep information in to make it easy to maintain the raid array. First... from the software raid howto, I've done the following.... sfdisk -d /dev/hda > /raidinfo/partitions.hda sfdisk -d /dev/hde > /raidinfo/partitions.hde So..........
  • A tun of trouble.... Sorry, VERY bad pun but I couldn't resist. I mentioned that I was having tun difficulties that kept me from playing around with anything fancy networking-wise with qemu. For starters let me see if I can explain what tun is. Tun is a method of creating a point-to-point "imaginary" network......
Blog Traffic Exchange Related Websites
  • Add Weight Loss and Fitness Bloggers to your Website Apparently this has ability has been built into wordpress for quite some time but a friend of mine recently pointed up that it can be done (pfblogs popular posts added to sidebar.)  Here is the wordpress codex for this feature: http://codex.wordpress.org/Function_Reference/fetch_rss. To add the latest weight loss health and fitness......
  • 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......
  • Schiff Considers Running For Senate and Advises US to Default on Its Debts Honestly In this past week's radio show, Peter Schiff seems to have taken a turn from his earlier, steadfast resistance to everyone's recommendations and support he run for US Senate.  For the first time now, Schiff concedes that he might run for Senate and that he is considering it.  Sites like......
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