LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-09-2014, 06:33 PM   #1
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
rc.local and rc.local_shutdown handling


It always bothered me to have to hand-manage my local startup and shutdown scripts since my needs are rather simple.

What do I mean by simple?
  1. I have additional scripts in /etc/rc.d that I want to run as part of startup and shutdown.
  2. All of these scripts have a "start" option.
  3. All of these scripts have a "stop" option.
  4. I want to run the stop scripts in the reverse order of the start scripts.
  5. I don't want to do anything else unique as part of my local startup.

If you have a setup like that which you would like to easily add and subtract such scripts from your start up, then continue reading. (If you don't, but want to read this anyways, then, umm, go ahead.)

Replace /etc/rc.d/rc.local with...
Code:
#! /bin/sh
# The standard way to start a service
# $1 is the name
# $2 is the log message
std_start() {
    if [ -x /etc/rc.d/rc.${1} ]; then
	if [ -z "${2}" ]; then
	    echo "starting ${1} service" | $LOGGER
	else
	    echo ${2} | $LOGGER
	fi
	/etc/rc.d/rc.${1} start
    fi
}

for i in $(/usr/bin/cat /etc/rc.d/local_services); do
    std_start $i
done
Add/replace /etc/rc.d/rc.local_shutdown with...
Code:
#! /bin/sh
# The standard way to stop a service
std_stop() {
    if [ -x /etc/rc.d/rc.${1} ]; then
	/etc/rc.d/rc.${1} stop
    fi
}

for i in $(/usr/bin/tac /etc/rc.d/local_services); do
    std_stop $i
done
In the file /etc/rc.d/local_services, put the services that you want to start in the order in which you want to start them, such as...
Code:
vde2
libvirt
postgresql
mongodb

There you go. "tac" and "cat" provide the real magic.

If you really do have unique things to run as part of start up and shut down, you could probably just add them at the beginning/end of /etc/rc.d/rc.local and /etc/rc.d/rc.local_shutdown as required.
 
Old 11-09-2014, 06:45 PM   #2
rkelsen
Senior Member
 
Registered: Sep 2004
Distribution: slackware
Posts: 4,541
Blog Entries: 7

Rep: Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621
Of course you realise that you can simply use SysVinit-style scripts to do this?

The only catch is that rc.sysvinit has to be executable, which I think it is by default nowadays.

The best part of it is that it not only meets every requirement in your list, but also enables easy packaging of software which requires something to be run at boot and saves you from reinventing the wheel.

I've said this before (and been routinely panned for it), but it really does make life easier.

Last edited by rkelsen; 11-09-2014 at 06:49 PM.
 
Old 11-09-2014, 08:09 PM   #3
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Original Poster
Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
You can change one file and provide the same functionality? I don't think that's the case.
 
Old 11-09-2014, 09:39 PM   #4
rkelsen
Senior Member
 
Registered: Sep 2004
Distribution: slackware
Posts: 4,541
Blog Entries: 7

Rep: Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621
One file plus a couple of symlinks...

Edit: Actually, to enable the functionality, you don't need to change anything. It's already there. You just need to put your custom rc script into /etc/rc.d/init.d/ and put a symlink to it under each runlevel directory at which you want it to run (/etc/rc.d/rc.3 for example). For shutdown, use rc.6 or rc.0, (which are the same thing under Slackware).

It is the neatest solution, IMO, since it's 100% reversible with the removepkg command.

Last edited by rkelsen; 11-09-2014 at 09:49 PM.
 
Old 11-09-2014, 11:07 PM   #5
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Original Poster
Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
To each their own.
 
2 members found this post helpful.
Old 11-10-2014, 12:25 AM   #6
j_v
Member
 
Registered: Oct 2011
Distribution: Slackware64
Posts: 364

Rep: Reputation: 67
Thanks for sharing. I may not use this right away, but I can see where this could work for me in a few places.
I realize that the rc.sysvinit works just fine, yet I like your approach.

Cheers,
John
 
Old 11-10-2014, 03:30 AM   #7
WiseDraco
Member
 
Registered: Nov 2006
Location: Europe,Latvia,Riga
Distribution: slackware,slax, OS X, exMandriva
Posts: 591

Rep: Reputation: 73
whats about mounting from rc.local, for example?
in that case, we can write, for example, commands with arguments and so on?
also, as i remember, in standart slack there is no file like rc.local_shutdown, as so in instruction not "change" but "create" must use?
 
Old 11-10-2014, 04:09 AM   #8
rkelsen
Senior Member
 
Registered: Sep 2004
Distribution: slackware
Posts: 4,541
Blog Entries: 7

Rep: Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621Reputation: 2621
Quote:
Originally Posted by Richard Cranium View Post
To each their own.
Yes, there are many ways to do things in Slackware.

Dropline Gnome used to leverage Slackware's SysVinit compatibility. If you'd like to see how they did it, you can download and examine one of their old HAL or DBUS packages from here: http://sourceforge.net/projects/drop...ckages/2.12.2/. Probably not a good idea to install it since it'll make other irreversible changes, but good to download and look at for the sake of this exercise.
 
1 members found this post helpful.
Old 11-10-2014, 04:27 AM   #9
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,959

Rep: Reputation: 5082Reputation: 5082Reputation: 5082Reputation: 5082Reputation: 5082Reputation: 5082Reputation: 5082Reputation: 5082Reputation: 5082Reputation: 5082Reputation: 5082
Shame slackware doesn't use a rc.conf. You could have just put it in rc.conf.local with all the other config changes,
rc.conf.local:
Code:
LOCAL_SERVICES="vde2 libvirt postgresql mongodb"
and then have rc/rc.M/rc.local or whatever, do a
Code:
for SERVICE in $LOCAL_SERVICES
do
  [ -x "/etc/rc.d/rc.$SERVICE" ]  &&  /etc/rc.d/rc.$SERVICE start
done
Then for shutdown, you could either write a simple function to use on the for loop to reverse the order, or have individual LOCAL_SERVICES_START= and LOCAL_SERVICES_STOP= lists in rc.conf (which would be something additional to maintain, but provides greater control over start/stop order).


I often wish slackware had gone with a bsd style rc.conf/rc.conf.local setup. It makes configuration so tidy.
 
2 members found this post helpful.
Old 11-10-2014, 02:37 PM   #10
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Original Poster
Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Quote:
Originally Posted by WiseDraco View Post
whats about mounting from rc.local, for example?
in that case, we can write, for example, commands with arguments and so on?
also, as i remember, in standart slack there is no file like rc.local_shutdown, as so in instruction not "change" but "create" must use?
I'm sure that you can expand what I did with little effort; it's pretty much a factor of how complicated you want the launching function to be.

There isn't a rc.local_shutdown by default, but if someone already *had* one and wanted to use this, then they would have to change their version.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rc.6 and rc.local_shutdown markush Slackware 6 03-29-2013 06:12 PM
'Housekeeping' with /etc/rc.d/rc.local_shutdown? andrew.46 Slackware 3 08-05-2008 07:59 PM
how can i add a local Folder on local Hard Disk as Yum Repository ?? vahid_p Fedora 4 02-22-2007 10:43 AM
Setup local machine to allow lan machines to retrieve its local user mail. Brian1 Linux - Networking 3 03-30-2006 05:04 AM
Local webserver -- How to deny all client install their local web server--Please help b:z Linux - Networking 13 04-16-2005 07:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 05:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration