You are not logged in.

#1 2010-10-26 05:35:03

kaitocracy
Forum Fellow
From: Durham, NC
Registered: 2010-04-21
Posts: 59
Website

Every RC script is the same

I've noticed that the vast majority of scripts in /etc/rc.d are essentially the same. They can all be replaced by this script below.

#!/bin/bash

source /etc/rc.conf
source /etc/rc.d/functions

name="$2"; path="`which $name 2> /dev/null`"
_wait='1'

if [ -x /etc/rc.d/$name ]; then
/etc/rc.d/$name $@; exit $?; fi

info="Usage: $0 (start|stop|restart) daemon"
[ -z "$name" ] ||
[ -z "$path" ] &&
echo $info && exit 1

[ -r /etc/conf.d/$name ] &&
  source /etc/conf.d/$name

PID=$(pidof -o %PPID "`readlink -f $path`")
case "$1" in
  start)
    stat_busy "Starting $name Daemon"
    [ -z "$PID" ] && $path $OPT &> /dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else stat_done; add_daemon $name
      echo $PID > /var/run/$name.pid
    fi ;;
  stop)
    stat_busy "Stopping $name Daemon"
    [ -z "$PID" ] || kill $PID &> /dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else stat_done; rm_daemon $name
      rm -f /var/run/$name.pid; fi ;;
  restart) $0 stop; sleep $_wait; $0 start ;;
esac

exit 0

Called for example like

./service start crond

And you could use this script transparently by dropping it in /sbin and patching /etc/rc.d/functions with

--- functions.backup    2010-10-26 01:39:30.660989232 -0400
+++ functions   2010-10-26 01:42:43.740987456 -0400
@@ -183,22 +183,29 @@
 ck_depends() {
        for daemon in $@; do
                if ck_daemon $daemon; then
-                       /etc/rc.d/$daemon start
+                        [ -x /etc/rc.d/$daemon ] && /etc/rc.d/$daemon start
+                        /sbin/service start $daemon
                fi
        done
 }

 start_daemon() {
-       /etc/rc.d/$1 start
+  [ -x /etc/rc.d/$1 ] && /etc/rc.d/$1 start
+  /sbin/service start $1
 }

 start_daemon_bkgd() {
-       stat_bkgd "Starting $1"
-       (/etc/rc.d/$1 start) &>/dev/null &
+  stat_bkgd "Starting $1"
+
+  [ -x /etc/rc.d/$1 ] &&
+  (/etc/rc.d/$1 start) &>/dev/null &
+
+  (/sbin/service start $1) &> /dev/null &
 }

 stop_daemon() {
-       /etc/rc.d/$1 stop
+  [ -x /etc/rc.d/$1 ] && /etc/rc.d/$1 stop
+  /sbin/service stop $1
 }

 # Status functions

Then maintainers who are lazy can just delete the repetitive rc.d scripts and users wouldn't even notice. Any thoughts?

Last edited by kaitocracy (2010-10-30 13:48:44)

Offline

#2 2010-10-26 05:43:00

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: Every RC script is the same

I guess that's similar to what some other distros do but we stick to the good old BSD style wink


neutral

Offline

#3 2010-10-26 09:13:43

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Every RC script is the same

You would need to include something to allow packages to 'override' this script with their own if required (eg, PostgreSQL does database initialization etc, as well as using "pg_ctl" to start instead of the 'postgres' or 'postgresql' commands)

if [ -x /etc/rc.d/$name ] ; then
  /etc/rc.d/$name $1
  exit $?
fi

Offline

#4 2010-10-26 10:40:56

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Every RC script is the same

To get feedback from the people who matter, submit this as a feature request on the bugtracker.

Offline

#5 2010-10-30 09:36:10

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: Every RC script is the same

I like this idea.  but what fukawi2 said.  There are a bunch of scripts that do something custom


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

Board footer

Powered by FluxBB