Re: Turning off services SOLVED

2001-01-07 Thread Matthew Sackman

On Sat, 6 Jan 2001 13:49:46 -0800, Ross Boylan said:

 At various times I have wanted to turn off certain daemons without
  uninstalling their packages.  I couldn't find any good way to do this,
  so I wrote a little script.  I'm making it available under the GPL.
  
  I've since discovered that the some packages also create a bunch of
  crontab jobs, and they are still cluttering things up a bit.
  
  If there's a better way to do this, I'd love to hear it.

Try finding the line in the file /etc/inet.conf and comment it out for the
services that you don't want to run. You may have to reboot then, or try
restarting the internet superserver - try a /etc/init.d/inetd restart. You
might have to kill a few other processes or just stop them using their scripts
in /etc/init.d/.

Hope this helps

  
  #! /usr/bin/python
  # switchDemon.py
  #
  # Usage: switchDemon.py (--on | --off) list of demon names
  #
  # This script will scan, turn off, or turn on selected
  # demons in /etc/rc?.d/.  It does so by renaming S* symbolic
  # links so the services won't start.
  # Scan mode (neither --on nor --off) simply reports the status
  # of the demons.
  # Note that demons are not actually started or stopped by this script;
  # it just controls what will happen at system startup.
  #
  # (c) 2001 Ross Boylan [EMAIL PROTECTED]
  # Made available under the GPL (see www.gnu.org)
  
  import glob, os.path, re, sys
  
  class Demon:
  Information and actions on a demon
  
  gDisabled = Disabled-
  
  def __init__(self, name):
  Name of demon
  if not os.path.exists(/etc/init.d/+name):
  raise name +  is not a known demon
  self._name = name
  self._statuses = []
  
  def checkStatus(self):
  Check status at various run levels
  self.doOverRunLevels(self._checkStatus)
  
  def turnOff(self):
  Make it so won't run at next system start
  self.doOverRunLevels(self._turnOff)
  self.checkStatus()
  
  def turnOn(self):
  We will start on next run level change
  self.doOverRunLevels(self._turnOn)
  self.checkStatus()
  
  def doOverRunLevels(self, method):
  Invoke method over all run levels
  for rl in glob.glob(/etc/rc[0-9Ss].d):
  method(rl, rl[-3])
  
  def _checkStatus(self, directory, runLevel):
  See if we are around and fill in _statuses if we are
  aRegex = re.compile((+Demon.gDisabled+r)?S(\d\d)+self._name);
  for file in os.listdir(directory):
  aMatch = aRegex.search(file)
  if aMatch:
  aStatus = DemonStatus(runLevel, aMatch.group(2), not 
 aMatch.group(1))
  self._statuses.append(aStatus)
  return
  
  def _turnOff(self, directory, runLevel):
  Disable demon for future reboots
  aRegex = re.compile(rS(\d\d)+self._name)
  for file in os.listdir(directory):
  aMatch = aRegex.match(file)  # must be at start
  if aMatch:
  os.rename(os.path.join(directory, file),
os.path.join(directory, Demon.gDisabled+file))
  # no return values documented for os.rename
  return
 
  def _turnOn(self, directory, runLevel):
  Enable demon for future reboots
  aRegex = re.compile(Demon.gDisabled+rS(\d\d)+self._name)
  for file in os.listdir(directory):
  aMatch = aRegex.match(file)  # must be at start
  if aMatch:
  os.rename(os.path.join(directory, file),
os.path.join(directory, 
 file[len(Demon.gDisabled):]))
  # no return values documented for os.rename
  return
  
  def reportTo(self, file):
  Send human readable report to stream
  file.write(Demon %s:\n%self._name)
  for aStatus in self._statuses:
  file.write(\t%s\n%str(aStatus))
  
  
  class DemonStatus:
  Status of a given demon
  
  def __init__(self, runlevel, priority, enabled=1):
  Priority (nn) of demon and whether it is enabled
  # runlevel is a single 0, 1, ...
  self._runlevel = runlevel
  self._priority = priority
  self._enabled = enabled
  
  def __str__(self):
  if self._enabled:
  msg = Enabled
  else:
  msg = Turned off
  return %s for run level %s (priority %s)%(msg, self._runlevel, 
 self._priority)
  
  def isEnabled(self):
  if self._enabled:
  return on
  else:
  return off
  
  
  aCommand = sys.argv[1]
  if aCommand[0] == -:
  if aCommand[-1] == f:
  anAction = turnOff
  elif aCommand[-1] == n:
  anAction = turnOn
  else:
  print Command not understood
  names = sys.argv[2:]
  else:
  anAction = 

Re: Turning off services SOLVED

2001-01-07 Thread Stefan Frank
Hi Ross!

On Sat, 06 Jan 2001, Ross Boylan wrote:

 At various times I have wanted to turn off certain daemons without
 uninstalling their packages.  I couldn't find any good way to do this,
 so I wrote a little script.  I'm making it available under the GPL.
 
 I've since discovered that the some packages also create a bunch of
 crontab jobs, and they are still cluttering things up a bit.
 
 If there's a better way to do this, I'd love to hear it.
 

Original script deleted.

What i'm doing usually is to rename the init-script under /etc/init.d/ to
original-filename.NO. This will affect all runlevels but i don't care.
IMO it's simple and quite obvious (for me at least).

Anyone got a better idea ?

Regards, Stefan



Re: Turning off services SOLVED

2001-01-07 Thread sena
On 07/01/2001 at 16:31 +0100, Stefan Frank wrote:
 What i'm doing usually is to rename the init-script under /etc/init.d/ to
 original-filename.NO. This will affect all runlevels but i don't care.
 IMO it's simple and quite obvious (for me at least).
 
 Anyone got a better idea ?
 
Debian has an excellent set of scripts for this and much more..

Why don't you do (as root) update-rc.d -f service-name remove and later,
when you want to enable it again, do a update-rc.d service-name defaults?

Simple, quick and effective. :)

Regards, sena...

-- 
[EMAIL PROTECTED], http://www.smux.net/~sena/
gpg fingerprint: F20B 12A8 A8F6 FD1F 9B1D BA62 C424 8E73 DD2E 47C8
SMUX - http://www.smux.net/



Re: Turning off services SOLVED

2001-01-07 Thread Arcady Genkin
Stefan Frank [EMAIL PROTECTED] writes:

 What i'm doing usually is to rename the init-script under /etc/init.d/ to
 original-filename.NO. This will affect all runlevels but i don't care.
 IMO it's simple and quite obvious (for me at least).
 
 Anyone got a better idea ?

What I do is ``chmod -x'' on the unwanted file in /etc/init.d/.  This
prevents them from being loaded.  Essentially the same thing as you
do, but I think that this way the script is going to be deleted if
the package it belongs to is removed.
-- 
Arcady Genkin
Don't read everything you believe.



Re: Turning off services SOLVED

2001-01-07 Thread mikpolniak

On Sun, 7 Jan 2001 15:52:17 +, sena said:

 On 07/01/2001 at 16:31 +0100, Stefan Frank wrote:
   What i'm doing usually is to rename the init-script under /etc/init.d/ to
   original-filename.NO. This will affect all runlevels but i don't care.
   IMO it's simple and quite obvious (for me at least).
   
   Anyone got a better idea ?
   
  Debian has an excellent set of scripts for this and much more..
  
  Why don't you do (as root) update-rc.d -f service-name remove and later,
  when you want to enable it again, do a update-rc.d service-name defaults?
  
  Simple, quick and effective. :)
  
Not that simple or effective when you need to reset the
links which are not defaults. You'll have to save the original non-
default runlevels and two-digit sequence code used by init to
decide which order to run the scripts in.
When defaults is used the service starts in runlevels 2345
and stops in 016 and the links will have sequence code 20.
You will need to explicitly specify anything that does not
have these default values. 
 



Re: Turning off services SOLVED

2001-01-07 Thread Dave Sherohman
On Sun, Jan 07, 2001 at 08:05:43AM +, Matthew Sackman wrote:
 Try finding the line in the file /etc/inet.conf and comment it out for the
 services that you don't want to run. You may have to reboot then, or try
 restarting the internet superserver - try a /etc/init.d/inetd restart. You
 might have to kill a few other processes or just stop them using their scripts
 in /etc/init.d/.

For servers that run from inetd, just edit inetd.conf and either
`/etc/init.d/inetd restart` (or `killall -HUP inetd`) to make inetd reread
its configuration.  No reboot is necessary.

For standalone servers, `/etc/init.d/server stop` will shut it down until
the next reboot (or runlevel change).  Follow that up with update-rc.d (read
the man page) if you want to disable it semi-permanently.

-- 
SGI products are used to create the 'Bugs' that entertain us in theatres
and at home. - SGI job posting
Geek Code 3.1:  GCS d? s+: a- C++ UL++$ P+ L+++ E- W--(++) N+ o+
!K w---$ O M- V? PS+ PE Y+ PGP t 5++ X+ R++ tv b+ DI D G e* h+ r y+



Re: Turning off services SOLVED

2001-01-07 Thread Ross Boylan

At 04:31 PM 1/7/2001 +0100, Stefan Frank wrote:

Hi Ross!

On Sat, 06 Jan 2001, Ross Boylan wrote:

 At various times I have wanted to turn off certain daemons without
 uninstalling their packages.  I couldn't find any good way to do this,
 so I wrote a little script.  I'm making it available under the GPL.

 I've since discovered that the some packages also create a bunch of
 crontab jobs, and they are still cluttering things up a bit.

 If there's a better way to do this, I'd love to hear it.


Original script deleted.

What i'm doing usually is to rename the init-script under /etc/init.d/ to
original-filename.NO. This will affect all runlevels but i don't care.
IMO it's simple and quite obvious (for me at least).

Anyone got a better idea ?

Regards, Stefan


Doesn't this have a few rough spots: you get a bunch of error messages on 
startup, and if you have started a service sometime after boot it won't be 
shut down automatically when you shut down?


On the update-rc.d idea (in another message): this only turns things off if 
the script they refer to is deleted.  But I wanted to keep it around.




Re: Turning off services SOLVED

2001-01-07 Thread Dave Sherohman
On Sun, Jan 07, 2001 at 11:51:55AM -0800, Ross Boylan wrote:
 On the update-rc.d idea (in another message): this only turns things off if 
 the script they refer to is deleted.  But I wanted to keep it around.

You apparently didn't read the man page like I suggested:

   -f Force  removal of symlinks even if /etc/init.d/name
  still exists.

-- 
SGI products are used to create the 'Bugs' that entertain us in theatres
and at home. - SGI job posting
Geek Code 3.1:  GCS d? s+: a- C++ UL++$ P+ L+++ E- W--(++) N+ o+
!K w---$ O M- V? PS+ PE Y+ PGP t 5++ X+ R++ tv b+ DI D G e* h+ r y+



Turning off services SOLVED

2001-01-06 Thread Ross Boylan
At various times I have wanted to turn off certain daemons without
uninstalling their packages.  I couldn't find any good way to do this,
so I wrote a little script.  I'm making it available under the GPL.

I've since discovered that the some packages also create a bunch of
crontab jobs, and they are still cluttering things up a bit.

If there's a better way to do this, I'd love to hear it.

#! /usr/bin/python
# switchDemon.py
#
# Usage: switchDemon.py (--on | --off) list of demon names
#
# This script will scan, turn off, or turn on selected
# demons in /etc/rc?.d/.  It does so by renaming S* symbolic
# links so the services won't start.
# Scan mode (neither --on nor --off) simply reports the status
# of the demons.
# Note that demons are not actually started or stopped by this script;
# it just controls what will happen at system startup.
#
# (c) 2001 Ross Boylan [EMAIL PROTECTED]
# Made available under the GPL (see www.gnu.org)

import glob, os.path, re, sys

class Demon:
Information and actions on a demon

gDisabled = Disabled-

def __init__(self, name):
Name of demon
if not os.path.exists(/etc/init.d/+name):
raise name +  is not a known demon
self._name = name
self._statuses = []

def checkStatus(self):
Check status at various run levels
self.doOverRunLevels(self._checkStatus)

def turnOff(self):
Make it so won't run at next system start
self.doOverRunLevels(self._turnOff)
self.checkStatus()

def turnOn(self):
We will start on next run level change
self.doOverRunLevels(self._turnOn)
self.checkStatus()

def doOverRunLevels(self, method):
Invoke method over all run levels
for rl in glob.glob(/etc/rc[0-9Ss].d):
method(rl, rl[-3])

def _checkStatus(self, directory, runLevel):
See if we are around and fill in _statuses if we are
aRegex = re.compile((+Demon.gDisabled+r)?S(\d\d)+self._name);
for file in os.listdir(directory):
aMatch = aRegex.search(file)
if aMatch:
aStatus = DemonStatus(runLevel, aMatch.group(2), not 
aMatch.group(1))
self._statuses.append(aStatus)
return

def _turnOff(self, directory, runLevel):
Disable demon for future reboots
aRegex = re.compile(rS(\d\d)+self._name)
for file in os.listdir(directory):
aMatch = aRegex.match(file)  # must be at start
if aMatch:
os.rename(os.path.join(directory, file),
  os.path.join(directory, Demon.gDisabled+file))
# no return values documented for os.rename
return
   
def _turnOn(self, directory, runLevel):
Enable demon for future reboots
aRegex = re.compile(Demon.gDisabled+rS(\d\d)+self._name)
for file in os.listdir(directory):
aMatch = aRegex.match(file)  # must be at start
if aMatch:
os.rename(os.path.join(directory, file),
  os.path.join(directory, file[len(Demon.gDisabled):]))
# no return values documented for os.rename
return

def reportTo(self, file):
Send human readable report to stream
file.write(Demon %s:\n%self._name)
for aStatus in self._statuses:
file.write(\t%s\n%str(aStatus))


class DemonStatus:
Status of a given demon

def __init__(self, runlevel, priority, enabled=1):
Priority (nn) of demon and whether it is enabled
# runlevel is a single 0, 1, ...
self._runlevel = runlevel
self._priority = priority
self._enabled = enabled

def __str__(self):
if self._enabled:
msg = Enabled
else:
msg = Turned off
return %s for run level %s (priority %s)%(msg, self._runlevel, 
self._priority)

def isEnabled(self):
if self._enabled:
return on
else:
return off


aCommand = sys.argv[1]
if aCommand[0] == -:
if aCommand[-1] == f:
anAction = turnOff
elif aCommand[-1] == n:
anAction = turnOn
else:
print Command not understood
names = sys.argv[2:]
else:
anAction = checkStatus
names = sys.argv[1:]

for aDemonName in names:
aDemon = Demon(aDemonName)
Demon.__dict__[anAction](aDemon)
aDemon.reportTo(sys.stdout)