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.
I have a task: install some software package. I have wrote SlackBuild which builds package. doinst.sh does some configuration actions. The second task of doinst.sh - to make software start automatically during system bootup(have ready /etc/rc.d/rc.mysoft script). A good place start it is /etc/rc.d/rc.local (and shutdown in /etc/rc.d/rc.local_shutdown).
Question: how to do it? How in bash/sh script correctly patch rc.local and rc.local_shutdown ? And how correctly unpatch it? I can do it manually, but I interested in automatic mechanism. The task is complicated by fact I'm going to install more than one of such (independent)packages, and start/stop sequences must be in strict order(i.e start A, then B, then C, then D, and this order should be strict independently of package installtion order).
The second task of doinst.sh - to make software start automatically during system bootup(have ready /etc/rc.d/rc.mysoft script).
Quote:
start/stop sequences must be in strict order(i.e start A, then B, then C, then D, and this order should be strict independently of package installtion order).
A common way is to edit /etc/rc.d/rc.local. Something like this:
if [ -x /etc/rc.d/rc.mysoft-A ]; then
/etc/rc.d/rc.mysoft-A start
fi
if [ -x /etc/rc.d/rc.mysoft-B ]; then
/etc/rc.d/rc.mysoft-B start
fi
if [ -x /etc/rc.d/rc.mysoft-C ]; then
/etc/rc.d/rc.mysoft-C start
fi
if [ -x /etc/rc.d/rc.mysoft-D ]; then
/etc/rc.d/rc.mysoft-D start
fi
Then ensure all the new scripts are executable (chmod +x).
If you want to methodically disable those processes when powering down and order is important, then edit rc.local_shutdown and reverse the order used in rc.local. Something like this:
if [ -x /etc/rc.d/rc.mysoft-D ]; then
/etc/rc.d/rc.mysoft-D stop
fi
if [ -x /etc/rc.d/rc.mysoft-C ]; then
/etc/rc.d/rc.mysoft-C stop
fi
if [ -x /etc/rc.d/rc.mysoft-B ]; then
/etc/rc.d/rc.mysoft-B stop
fi
if [ -x /etc/rc.d/rc.mysoft-A ]; then
/etc/rc.d/rc.mysoft-A stop
fi
Woodsman, I know how to edit rc.local and rc.local_shutdown using vi or other interactive editor! I know how to type "chmod +x /etc/rc.d/rc.mysoft" with my hands in shell also.
I need it to be done by script automatically. I.e. I type ./install-init-scripts.sh (or it will be part of doinst.sh) and this script must do next:
1. Find /etc/rc.d/rc.local and /etc/rc.d/rc.local_shutdown (is not present - create them)
2. Check if there is already present start/stop loader (i.e if [ -x ... ]; then with target starter and stopper) and if check is failed, it should insert it into right place
3. It must ensure the start/stop load is placed on right place i.e B must be run before C and after A.
This script should do it automatically without interaction with user. That is my problem.
Yes, I know I can use SysV style runlevel management, but it is not an option in my case(it is a crutch).
Could maybe do something like this in the doinst.sh
Code:
if ! grep -q '^#Added automatically by mysoft$' etc/rc.d/rc.local ; then
cat <<EOF >> etc/rc.d/rc.local
#Added automatically by mysoft
if [ -x /etc/rc.d/rc.mysoft ]; then
/etc/rc.d/rc.mysoft start
fi
EOF
fi
edit: That's not quite what you want. I apologize for only skimming through this thread before replying.
Last edited by piratesmack; 07-20-2011 at 01:08 AM.
Hello
I have a task: install some software package. I have wrote SlackBuild which builds package. doinst.sh does some configuration actions. The second task of doinst.sh - to make software start automatically during system bootup(have ready /etc/rc.d/rc.mysoft script). A good place start it is /etc/rc.d/rc.local (and shutdown in /etc/rc.d/rc.local_shutdown).
Question: how to do it? How in bash/sh script correctly patch rc.local and rc.local_shutdown ? And how correctly unpatch it? I can do it manually, but I interested in automatic mechanism. The task is complicated by fact I'm going to install more than one of such (independent)packages, and start/stop sequences must be in strict order(i.e start A, then B, then C, then D, and this order should be strict independently of package installtion order).
Since you state that task(s) can be performed manually from the console then;
Quote:
excerpt 'man script';
script -- make typescript of terminal session
DESCRIPTION
Script makes a typescript of everything printed on your terminal. It is useful for
students who need a hardcopy record of an interactive session as proof of an assign-
ment, as the typescript file can be printed out later with lpr(1).
If the argument file is given, script saves all dialogue in file. If no file name is
given, the typescript is saved in the file typescript.
Options:
-a Append the output to file or typescript, retaining the prior contents.
'script -a' will output your entries to typescript or you could designate a filename.
That way you have a start for creating a script. Sure you will need to perform conditional and script format to get things going. It is a start since you can manually do the task(s).
Just a few links to aid you to gaining some understanding;
So any of the packages installations can insert the code Woodsman suggested as piratesmack suggested. For uninstalling, either the code could be removed by the last package out (each installation would need a mechanism to detect any of the other packages) or it could be left there; the if [ -x tests would render it ineffective. If you go for the first option it would be helpful to add a comment line telling the user not to modify any of the inserted/appended lines if they want the uninstallation procedure to be effective.
if ! grep -q '/etc/rc.d/rc.mysoft start' etc/rc.d/rc.local |grep -v # ; then
cat <<EOF >> etc/rc.d/rc.local
#Added automatically by mysoft
if [ -x /etc/rc.d/rc.mysoft ]; then
/etc/rc.d/rc.mysoft start
fi
EOF
fi
so that the doinst checks specifically for the rc.mysoft entry -this allows you to use similar code for other scripts. The 'grep -v #' filters out any commented entries. src2pkg automatically creates such doinst code for any non-standard package which contains an rc.* file. The same sort of thing could be done for local_shutdown, but as already pointed out, the code checks if the rc.* is executable which implies that it is present.
Unfortunately this does *not* work for multiple services which must be started in a certain order unless they are installed in the correct order. If the services are all interdependent, then you could devise some code within the main rc.* file which would take care of starting all the services in the correct order. Slackware package management doesn't help you at all here since it doesn't understand dependencies.
Unfortunately this does *not* work for multiple services which must be started in a certain order unless they are installed in the correct order. If the services are all interdependent, then you could devise some code within the main rc.* file which would take care of starting all the services in the correct order. Slackware package management doesn't help you at all here since it doesn't understand dependencies.
How about any of the interdependent-sequence packages installs the startup commands in the correct sequence for the whole set? The if [ -x tests mean the code is ineffectual for any not installed.
Good ideas fellows. Anything that will help get things running correctly and that can be installed programatically -here we see an example of why slack doesn't try managing dependencies...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.