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
  • 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......
  • 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......
  • Remote Tech Support with x11vnc and wrapper script So, the idea is that I wanted something "like" the Ultranvnc Single Click download, only for linux. The main idea being is that if someone is looking for a bit of desktop tech support on linux, we don't need to be giving instructions for 5 different package managers, or source......
Blog Traffic Exchange Related Websites
  • 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......
  • 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......
  • 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