LinuxQuestions.org
Help answer threads with 0 replies.
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 08-19-2014, 12:22 PM   #1
r41d3n
Member
 
Registered: Mar 2013
Distribution: Arch
Posts: 42

Rep: Reputation: Disabled
Problem executing /etc/rc.d/rc.local scripts


Hi,

I came into a problem today when I added a new script to /etc/rc.d/rc.local like the usual way:

Code:
if [ -x /etc/rc.d/rc.program ]; then
  . /etc/rc.d/rc.program start
fi
When I rebooted my machine, the script wasn't executed. I revised my script, rc.local and other files in /etc but I didn't could find an answer to the problem. I googled the net and the forum, but didn't find nothing related. After some tests I removed the dot "." in the beginning of the line of all my scripts in rc.local and rc.local_shutdown and voilą. All my scripts could be executed normally, so the problem was the dot in the line starting the program script. The correct form is:

Code:
if [ -x /etc/rc.d/rc.program ]; then
  /etc/rc.d/rc.program start
fi
I was thinking that rc.local on Slackware had a limit of scripts, but the problem was that when you use the dot ".", you can execute only 3 scripts (at least in my case). Someone can give some directions where to find more info about this?

Thanks
 
Old 08-19-2014, 12:30 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
. <filename> means source and execute <filename> in the current shell, I am not aware of execution limit..
Code:
help .
Edit, maybe you have an "exit" or something that log off the shell in one of your scripts?

Last edited by keefaz; 08-19-2014 at 12:36 PM.
 
Old 08-20-2014, 08:44 AM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
As @keefaz says, the "dot command" runs in the current shell (which is handy for setting environment variables on the fly that will "stick" until the current shell exits). Every other executable forks and executes in a new shell (including every time you type a command and hit the enter key).

My /etc/rc.d/rc.local starts up a bunch of stuff:
Code:
[
cat rc.local
#!/bin/sh
#
# /etc/rc.d/rc.local:  Local system initialization script.
#
# Put any local startup commands in here.  Also, if you have
# anything that needs to be run at shutdown time you can
# make an /etc/rc.d/rc.local_shutdown script and put those
# commands in there.

# Start apcupsd
if [ -x /etc/rc.d/rc.apcupsd ]; then
	/etc/rc.d/rc.apcupsd start
fi

# Start postgresql
if [ -x /etc/rc.d/rc.postgresql ]; then
	/etc/rc.d/rc.postgresql start
fi

# Start tomcat
if [ -x /etc/rc.d/rc.tomcat ]; then
	/etc/rc.d/rc.tomcat start
fi

# Start vboxdrv
# If you do not wish this to be executed here then comment it out,
# and the installer will skip it next time.
if [ -x /etc/rc.d/rc.vboxdrv ]; then
    /etc/rc.d/rc.vboxdrv start
fi

# Start vboxballoonctrl-service
# If you do not wish this to be executed here then comment it out,
# and the installer will skip it next time.
if [ -x /etc/rc.d/rc.vboxballoonctrl-service ]; then
    /etc/rc.d/rc.vboxballoonctrl-service start
fi

# Start vboxautostart-service
# If you do not wish this to be executed here then comment it out,
# and the installer will skip it next time.
if [ -x /etc/rc.d/rc.vboxautostart-service ]; then
    /etc/rc.d/rc.vboxautostart-service start
fi

# Start vboxweb-service
# If you do not wish this to be executed here then comment it out,
# and the installer will skip it next time.
if [ -x /etc/rc.d/rc.vboxweb-service ]; then
    /etc/rc.d/rc.vboxweb-service start
fi
Note: no exits. The commands that are executed start daemons, which fork and exec a child process, the parent dies, but the daemon process continues to run until the system is shut down. By including an exit, you're killing the parent process (which is the process that runs everything in /etc/rc.d/rc.local). You don't want that to happen, so don't include exits (and don't include "dot commands" either unless you really know the consequences of doing so).

If you execute
Code:
ps -efl | pg
F S UID        PID  PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
4 S root         1     0  0  80   0 -  1088 poll_s Aug09 ?        00:00:05 init [3]       
1 S root         2     0  0  80   0 -     0 kthrea Aug09 ?        00:00:00 [kthreadd]
1 S root         3     2  0  80   0 -     0 smpboo Aug09 ?        00:00:01 [ksoftirqd/0]
1 S root         5     2  0  60 -20 -     0 worker Aug09 ?        00:00:00 [kworker/0:0H]
1 S root         7     2  0 -40   - -     0 smpboo Aug09 ?        00:00:00 [migration/0]
1 S root         8     2  0  80   0 -     0 rcu_gp Aug09 ?        00:00:00 [rcu_bh]
1 S root         9     2  0  80   0 -     0 rcu_gp Aug09 ?        00:01:42 [rcu_sched]
1 S root        10     2  0 -40   - -     0 smpboo Aug09 ?        00:00:00 [migration/1]
1 S root        11     2  0  80   0 -     0 smpboo Aug09 ?        00:00:00 [ksoftirqd/1]
1 S root        13     2  0  60 -20 -     0 worker Aug09 ?        00:00:00 [kworker/1:0H]
The PID is the daemon process identification number, the PPID is the parent process identification number (this list is really abbreviated, it's multiple pages long). PID 1 is init, PPID 0 is the kernel (you don't want to exit either of those) and all the rest are the daemons that provide services.

Hope this helps some.
 
2 members found this post helpful.
Old 08-20-2014, 12:38 PM   #4
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,860

Rep: Reputation: 2228Reputation: 2228Reputation: 2228Reputation: 2228Reputation: 2228Reputation: 2228Reputation: 2228Reputation: 2228Reputation: 2228Reputation: 2228Reputation: 2228
I got tired of always typing in the "start me if I'm executable" boilerplate (even in emacs), so I wrapped it in a function at the top of /etc/rc.d/rc.local. Your code snippet would look like...
Code:
# 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
}

std_start apcupsd
std_start tomcat
std_start vboxdrv
std_start vboxballoonctrl-service
std_start vboxautostart-service
std_start vboxweb-service
I have a std_stop function in /etc/rc.d/rc.local_shutdown that looks very similar.
 
4 members found this post helpful.
  


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
[SOLVED] Konqueror updates to local files / executing local binaries dogpatch Linux - General 1 01-12-2011 03:58 PM
Problem executing scripts from cron. glore2002 Debian 6 10-01-2009 10:40 AM
problem executing scripts mierdatuti Linux - General 4 09-19-2008 04:21 AM
problem executing user created scripts on console farooqmaniar Linux - Software 1 01-12-2006 06:06 PM
problem executing scripts on mounted fat32 partition roald Linux - General 8 06-14-2004 06:02 AM

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

All times are GMT -5. The time now is 06:16 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