Is it safe to modify init scripts like rc.0/rc.6 on Slackware?
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is it safe to modify init scripts like rc.0/rc.6 on Slackware?
I need to modify the shutdown behaviour of a Slackware system, specifically I need to instruct a UPS controlled using nut to shutdown the inverter and related.
rc.local_shutdown is called to early for this to work, is it safe to modify rc.0/rc.6 directly, or will they just be overwritten on the next sysvinit update?
"Safe" is a relative word. As long as you don't botch anything, you can make any edits you want to the startup/shutdown files. However, if you do it wrong, it is possible to prevent proper startup/shutdown procedures from occurring.
I don't say that to dissuade you from editing them, just giving you the info
The Slackware startup/shutdown scripts are good defaults and work for most people. However, there will always be cases that some users will need to edit the scripts, so don't worry about that.
Quote:
Originally Posted by maxf130
or will they just be overwritten on the next sysvinit update?
If you check the SlackBuild for sysvinit-scripts, it states the following:
Code:
# Install Slackware scripts and config files from $CWD/scripts/:
mkdir -p $PKG/etc/rc.d
for file in rc.{4,6,K,M,S} rc.cpufreq rc.local rc.loop rc.sysvinit rc.modules rc.modules.local ; do
cp -a $CWD/scripts/$file $PKG/etc/rc.d/${file}.new
chmod 755 $PKG/etc/rc.d/${file}.new
chown root:root $PKG/etc/rc.d/${file}.new
done
The key thing here is that they're being copied as .new files. That means that when the package is upgraded, it will check the existing files and if they aren't the same, it will keep the new files as .new and your existing files as the original. If you use slackpkg, it will prompt you to deal with these new files.
Although, in general, if you make complex edits to complex files like some of the rc scripts, I'd recommend writing down what you did (or maybe making a diff). That way, if something goes wrong, you're able to easily see what you did (whether it is to restore or revert the changes).
I would suggest making a 'simple' edit to the script that will be easy to merge with future distro releases of the script, this will show up as a .new file as others have mention when that package is installed.
If you need something to run at the very end of the script consider adding something like:
Code:
if [ -d /etc/rc.d/shutdown_local ]; then
for I in /etc/rc.d/shutdown_local/*; do
if [ -x $I ]; then
. "$I"
fi
done
fi
then create an /etc/rc.d/shutdown_local directory and put your complex logic in files located there, set to execute obviously. If nothing else it will help manage the variable scope and ensure the 'hard parts' of what you are trying to do never accidentally get overwritten.
If you're going to do that, I would probably suggest using /etc/rc.d/rc.local_shutdown.d/ as similar directories in /etc/ typically contain a .d after the name (see /etc/X11/xorg.conf.d/, /etc/profile.d/, /etc/cron.d/, /etc/modprobe.d/, etc), and the rc. follows the standard naming convention for Runtime Configuration.
But these are just my opinions. I don't know of any standardized naming conventions for this scenario.
Luckily, I don't have anything that needs this type of complexity
bassmadrigal is of course right, if you are doing this on a single personal system than it probably does not matter. If it a business system or might ever be maintained by someone else his suggestion is a good one. Even if the naming convention might not apply perfectly here it will at least give someone a general clue as to what you did.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.