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:
Why is this useful?
(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 ?
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
(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)
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 ...
Sorry for reopening the bug, but i need to reply on comment 5
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) ?
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 ...
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
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.
*** Bug 98807 has been marked as a duplicate of this bug. ***