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
  • 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......
  • 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
  • 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?......
  • 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......
  • 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......
www.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