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
  • 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......
  • Mandriva 2006 upgrade on Inspiron 8000 laptop saga Part I I had a chance today to start the upgrade process for Mandriva 2006 on my laptop (Dell Inspiron 8000). Now, let's see.... a bit of background. Mandriva (Mandrive/Mandrake) has been my favorite distro since converting to linux several years back (around Mandrake 8.1 or 8.2) I've had it running on......
  • 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......
Blog Traffic Exchange Related Websites
  • Add Latest Golf Posts 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 golf posts to my sidebar......
  • 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......
  • US Broadband Internet Satellite Scheduled for Launch in 2011 A California satellite technology provider has signed a deal to put a planned broadband Internet satellite into orbit above the U.S. in the first half of 2011. The ViaSat-1 satellite will be launched on board an Arianespace rocket from the European space port in Kourou, French Guiana, according to the......
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