Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 98261 - switch initscript controlled by files in conf.d where user puts command that execute when runlevel changes
Summary: switch initscript controlled by files in conf.d where user puts command that ...
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: All Linux
: High enhancement
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
: 98807 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-07-07 12:21 UTC by Nikolas Garofil
Modified: 2006-11-11 00:10 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nikolas Garofil 2005-07-07 12:21:02 UTC
We all know the "local" initscript used to start commands that should be
executed at the end of boot and at the start of the shutdown.
But the problem is that we don't have something to execute commands when we
change the runlevel.
My proposal is creating a special initscript "switch" that gets executed:
- at boot
- at shutdown
- when the runlevel gets switched
This script shouldn't be a standalone script in "/etc/init.d" but it should be a
part of "/sbin/rc". The now /sbin/rc should work as follows:
1 Check the name of the current runlevel
2 Check the name of the asked runlevel
3 Execute /etc/conf.d/switch.name-of-current-runlevel.stop
4 Execute the old /sbin/rc that stops the initscripts of the current runlevel
that are not in the not asked runlevel and starts those of the asked that are
not in the current
5 At the end of /sbin/rc execute /etc/conf.d/switch.name-of-asked-runlevel.start

Is something like this already in development ?
If it is not already in development and if I would write this new version of
/sbin/rc would it be accepted ?
If I should write a new version of rc should I base it on the ~ARCH version or
can I find a even newer version somewhere ?

Reproducible: Always
Steps to Reproduce:
Comment 1 Grant Goodyear (RETIRED) gentoo-dev 2005-07-07 13:21:55 UTC
Why is this useful?
Comment 2 Nikolas Garofil 2005-07-07 13:44:45 UTC
(In reply to comment #1)
> Why is this useful?
Let me answer with another question: Why is local useful ?
I have some commands that I want to execute when I go to a specific runlevel and
I am probably not the only one. Those commands are to small to write a whole
initscript for it.
So, what are the answers on my 3 questions ?
Comment 3 SpanKY gentoo-dev 2005-07-07 15:09:15 UTC
so why not create some init scripts specific to each run level

<level>.local

then add each <level>.local to <level> and it should work
Comment 4 Nikolas Garofil 2005-07-07 15:46:10 UTC
(In reply to comment #3)
> so why not create some init scripts specific to each run level
> 
> <level>.local
> 
> then add each <level>.local to <level> and it should work

This would also work, but if you do it like this then the administrator will
have to create/remove <level>.local scripts in /etc/init.d when he
creates/removes runlevels. If we do it my way then he only has to worry about
the files in /etc/conf.d.

BTW, I forgot to mention that people that don't use "switch" will not notice
that it exist. So the only disadvantage for people that don't use it is that
running rc will take a couple microseconds longer. (rc will check if
/etc/conf.d/switch.name-of-current-runlevel.stop and
/etc/conf.d/switch.name-of-asked-runlevel.start exist)
Comment 5 Martin Schlemmer (RETIRED) gentoo-dev 2005-07-07 16:05:57 UTC
The problem is this will add more logic that have to be maintained and kept
track of when we do major rewrites, etc, that can be done perfectly already with
just a line or two extra, and in theory one less file (only one rcscript, not a
.start and .stop).

Actually - you can do it yourself with one script .. take the local script for
example, and just change it to test for
/etc/conf.d/switch.${SOFTLEVEL}.{start,stop}, etc ...
Comment 6 Nikolas Garofil 2005-07-07 16:20:17 UTC
Sorry for reopening the bug, but i need to reply on comment 5
Comment 7 Nikolas Garofil 2005-07-07 16:28:56 UTC
Sorry that this comment and comment 6 are not in 1 comment but I am a bugzilla
newbie.

In reply te comment 5:
It is impossible to do this in local because local doesn't always run start and
stop when you change the runlevel (there is a (BIG) chance that the old and the
new runlevel both contain or both not contain local) so this has to be fixed
with extra init scripts (a ugly hack) or by adding this new feature to rc.

Do not worry, I am willing to write this myself, but my question is : Will it
get accepted (after heavy testing ofcours) ?
Comment 8 Martin Schlemmer (RETIRED) gentoo-dev 2005-07-07 16:47:59 UTC
OK, here is a script switch:

------
#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

depend() {
        after *
}

start() {
        ebegin "Starting switch.${SOFTLEVEL}"

        # Add any misc programs that should be started
        # to /etc/conf.d/local.start
        if [[ -e /etc/conf.d/switch.${SOFTLEVEL}.start ]] ; then
                source /etc/conf.d/switch.${SOFTLEVEL}.start
        fi

        eend $? "Failed to start switch.${SOFTLEVEL}"
}

stop() {
        ebegin "Stopping switch.${SOFTLEVEL}"

        # Add any misc programs that should be stopped
        # to /etc/conf.d/local.stop
        if [[ -e /etc/conf.d/switch.${SOFTLEVEL}.stop ]] ; then
                source /etc/conf.d/switch.${SOFTLEVEL}.stop
        fi

        eend $? "Failed to stop switch.${SOFTLEVEL}"
}


# vim:ts=4
-----

Say you have runlevels 'work' and 'home', then:
- cp it to /etc/init.d/switch.work and /etc/init.d/switch.home
  (or symlink it)
- rc-update add switch.work work; rc-update add switch.home home
- create /etc/conf.d/switch.*.{start,stop}

This is what I meant ...
Comment 9 Nikolas Garofil 2005-07-08 01:04:14 UTC
I must admit : This is a very nice solution ! I would suggest to:
-let baselayout create /etc/init.d/switch.default,
/etc/conf.d/switch.default.start and /etc/conf.d/switch.default.stop
-put "use local" in /etc/init.d/switch.default because they both contain "after
*". I am not sure how "depend,need,use,after and before" get checked so I am not
sure that this will work, but if it won't work then there's probably another
easy solution
-update the documentation

/etc/conf.d/switch.default.start could contain something like this:
# This is a good place to put commands that should be executed
# at the end of the boot AND when the system changes to this runlevel

/etc/conf.d/switch.default.stop could contain something like this:
# This is a good place to put commands that should be executed
# at the beginning of the shutdown AND when the system changes to
# another runlevel then this one

Also a command "create-runlevel" could be handy:
----------------------------------------------
#!/bin/bash
if [ $UID != 0  ] ; then
       echo "Execute this as root"
       exit 1
fi
if [ $# != 1 ] ; then
        echo "SYNTAX: $0 name_of_new_runlevel"
        exit 1
fi
if [ -e /etc/runlevels/$1 ] ; then
        echo "Runlevel $1 already exists"
        exit 1
fi
mkdir /etc/runlevels/$1
if [ -e /etc/conf.d/switch.$1.start ] ; then
        echo "/etc/conf.d/switch.$1.start already exists, check the content"
else
        cp /etc/conf.d/switch.default.start /etc/conf.d/switch.$1.start
fi
if [ -e /etc/conf.d/switch.$1.stop ] ; then
        echo "/etc/conf.d/switch.$1.stop already exists, check the content"
else
        cp /etc/conf.d/switch.default.stop /etc/conf.d/switch.$1.stop
fi
if [ -e /etc/init.d/switch.$1 ] ; then
        echo "/etc/init.d/switch.$1 already exists, check if it is hardlink to
/etc/init.d/switch.default"
else
        ln /etc/init.d/switch.default /etc/init.d/switch.$1
fi
ln -s /etc/init.d/switch.$1 /etc/runlevels/$1/switch.$1
ln -s /etc/init.d/local /etc/runlevels/$1/local
echo "Runlevel $1 created"
--------------------------------
The initscripts are hardlinked so that they all get updated if there is a update
Comment 10 Martin Schlemmer (RETIRED) gentoo-dev 2005-07-08 01:49:09 UTC
And this is why we say its not needed to add support baselayout side, as the
user can do something like this if he really wants to without additional support.
Comment 11 SpanKY gentoo-dev 2005-07-12 15:15:24 UTC
*** Bug 98807 has been marked as a duplicate of this bug. ***
Comment 12 SpanKY gentoo-dev 2006-11-11 00:10:36 UTC
*** Bug 98807 has been marked as a duplicate of this bug. ***