Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
Apress - Books for Professionals by Professionals

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents

· Introduction to Operating Systems
· Linux Basics
· Working with the System
· Shells and Utilities
· Editing Files
· Basic Administration
· The Operating System
· The X Windowing System
· The Computer Itself
· Networking
· System Monitoring
· Solving Problems
· Security
· Installing and Upgrading
· Linux and Windows

Glossary
MoreInfo
Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
FAQ
Copyright Info
Terms of Use
Privacy Info
Disclaimer
WorkBoard
Thanks
Donations
Advertising
Masthead / Impressum
Your Account

Communication
Feedback
Forums
Private Messages
Surveys

Features
HOWTOs
News Archive
Submit News
Topics
User Articles
Web Links

Google
Google


The Web
linux-tutorial.info

Who's Online
There are currently, 193 guest(s) and 0 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here

  
Linux Knowledge Base and Tutorial: Forums



Linux Tutorial :: View topic - Running a script at startup
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Running a script at startup
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Linux Tutorial Forum Index -> How To
View previous topic :: View next topic  
Author Message
swadams
Beginner


Joined: Aug 24, 2005
Posts: 12

PostPosted: Wed Aug 24, 2005 8:58 pm    Post subject: Running a script at startup Reply with quote

I'm trying to get a script to run at startup. I have a link to it in rc5.d and the computer starts in run level 5. The script itself works if I run it manually. The script has the same ownership and permissions as others that run at startup. The name of the link in rc5.d starts with an S as it should. What else could be wrong?
Back to top
View user's profile Send private message
swadams
Beginner


Joined: Aug 24, 2005
Posts: 12

PostPosted: Wed Aug 24, 2005 9:51 pm    Post subject: Reply with quote

The script itself isn't the problem. It runs at startup on another computer. Doing the same thing that worked on the first computer isn't working on the second. The one it works on runs Red Hat and the other one runs SUSE, if that tells you anything.
Back to top
View user's profile Send private message
jimmo
Administrator


Joined: Jul 27, 2002
Posts: 309
Location: Coburg, Germany

PostPosted: Thu Aug 25, 2005 5:20 am    Post subject: Reply with quote

I think ffreeloader is heading in the right direction, if everything else is correct.

Not to be much more obnoxious that usual, but you haven't said much about the problem. Looking at the script, it seems that it doesn't do much. In fact, it doesn't seem to do anything at all. So, I am curious as to how you know it is not working? The script does nothing when you run it manually, the script does nothing when the system goes into run-level 5, so it seems to me it does what you want. Wink

Are you getting any error messages on the screen when you boot indicating a problem with this particular script?

When you start it manually, how exactly do you do it? Do you switch into /etc/init.d/ and start it with "./script"? Or do you use the full path to the script in "/etc/init.d/rc5.d/script.sh"? Could be a path problem.

Is it that the system does not even find the script and does not start it or that the system tries to start the script and fails?

Try putting a "set -x" into the script /etc/init.d/rc as well as your script. This will show you each step that it takes, i.e. which commands are being executed.

The bottom line is that we need to figure where in the process it is failing.
Back to top
View user's profile Send private message
swadams
Beginner


Joined: Aug 24, 2005
Posts: 12

PostPosted: Thu Aug 25, 2005 3:27 pm    Post subject: Reply with quote

I never posted the script. It starts PostgreSQL, so yes, I know if it's working.
Back to top
View user's profile Send private message
swadams
Beginner


Joined: Aug 24, 2005
Posts: 12

PostPosted: Thu Aug 25, 2005 3:45 pm    Post subject: Reply with quote

I tried running the link in rc5.d and it worked. Also, other scripts in the same directory run at startup.
Back to top
View user's profile Send private message
jimmo
Administrator


Joined: Jul 27, 2002
Posts: 309
Location: Coburg, Germany

PostPosted: Thu Aug 25, 2005 4:35 pm    Post subject: Reply with quote

[quote="tripwire45"]jimmo, if you are referring to the script I posted above, I just put that there as an example of the proper syntax (I hope). [/quote]

Embarassed That was [b]my[/b] mistake. I answered it without really paying attention. Sorry, everyone.
Back to top
View user's profile Send private message
jimmo
Administrator


Joined: Jul 27, 2002
Posts: 309
Location: Coburg, Germany

PostPosted: Thu Aug 25, 2005 4:42 pm    Post subject: Reply with quote

[quote="swadams"]I tried running the link in rc5.d and it worked. Also, other scripts in the same directory run at startup.[/quote]

We still don't know what the system is saying when it doesn't start. That will definately give us clues as to what is going on. Maybe there is another service PostgreSQL, but PostgreSQL starts first. Put the "set -x" in the scripts, reboot the machine and tells us what messages it brings.
Back to top
View user's profile Send private message
swadams
Beginner


Joined: Aug 24, 2005
Posts: 12

PostPosted: Thu Aug 25, 2005 4:49 pm    Post subject: Reply with quote

The script isn't running at all at startup. It currently prints, "Starting PostgreSQL" and this isn't printed at startup.
Back to top
View user's profile Send private message
swadams
Beginner


Joined: Aug 24, 2005
Posts: 12

PostPosted: Thu Aug 25, 2005 10:42 pm    Post subject: Reply with quote

PostgreSQL itself works fine. I just have to run the script manually instead of it running at startup.
Back to top
View user's profile Send private message
swadams
Beginner


Joined: Aug 24, 2005
Posts: 12

PostPosted: Thu Aug 25, 2005 11:32 pm    Post subject: Reply with quote

It's 8.0.3.
Back to top
View user's profile Send private message
jimmo
Administrator


Joined: Jul 27, 2002
Posts: 309
Location: Coburg, Germany

PostPosted: Fri Aug 26, 2005 3:30 pm    Post subject: Reply with quote

I don't want to appear any more obnoxious that usual, but you just keep saying more or less that the script does not work and not much more.

[quote]
The script isn't running at all at startup. It currently prints, "Starting PostgreSQL" and this isn't printed at startup.
[/quote]

So far you have not said anything to support the statement that the script isn't running at all. Just because you do not see "Starting PostgreSQL" does [b]not[/b] mean the script is not starting. The fact that ProgreSQL does not start does [b]not[/b] mean the script is not starting. It only means that the script never reaches the part of the script that prints that line. That is a [b]very[/b] important difference.

Maybe the default path is not set correctly, so run from the command line it finds something it needs to start, but not when started from the rc-scripts. If you are dealing with two different Linux versions, the default paths maybe different and the script [b]is[/b] the problem as you need to explicitely set the path. I have had the exact same problem with Oracle.

Maybe something needs to be loaded first but isn't. When you finally get to the command line, that "something" has been loaded and things work fine.

If you put a "set -x" into the scripts you will see every single step the script takes. If everything you say is correct, then for me the only logical conclusion is that the script [b]is[/b] getting started but cannot continue for some reason.

Since we have not seen the inside of the script, nor have we seen what is actually being done, we can only guess and that is not very constructive.

Unfortunately, I must agree with ffreeloader

[quote]
... it seems you are providing as little information as possible. Not exactly the behavior of someone who's really wanting to be helped.
[/quote]

How about doing what we ask so that we [b]can[/b] help you?
Back to top
View user's profile Send private message
swadams
Beginner


Joined: Aug 24, 2005
Posts: 12

PostPosted: Fri Aug 26, 2005 3:50 pm    Post subject: Reply with quote

You said, "you just keep saying more or less that the script does not work and not much more. " I haven't said that. In fact, I've said more than once that the script itself isn't bugged. Running it manually works perfectly. I've also said that it runs at startup on another computer, just not on the one that uses SUSE. And yes, I can run it manually on either computer. I'm not asking for advice on debugging the script itself.

Here's the script anyway, with the password deleted, of course.

#! /bin/sh

# chkconfig: 2345 98 02
# description: PostgreSQL RDBMS

# This is an example of a start/stop script for SysV-style init, such
# as is used on Linux systems. You should edit some of the variables
# and maybe the 'echo' commands.
#
# Place this file at /etc/init.d/postgresql (or
# /etc/rc.d/init.d/postgresql) and make symlinks to
# /etc/rc.d/rc0.d/K02postgresql
# /etc/rc.d/rc1.d/K02postgresql
# /etc/rc.d/rc2.d/K02postgresql
# /etc/rc.d/rc3.d/S98postgresql
# /etc/rc.d/rc4.d/S98postgresql
# /etc/rc.d/rc5.d/S98postgresql
# Or, if you have chkconfig, simply:
# chkconfig --add postgresql
#
# Proper init scripts on Linux systems normally require setting lock
# and pid files under /var/run as well as reacting to network
# settings, so you should treat this with care.

# Original author: Ryan Kirkpatrick <pgsql@rkirkpat.net>
# $PostgreSQL: pgsql/contrib/start-scripts/linux,v 1.7 2004/10/01 18:30:21 tgl Exp $
## EDIT FROM HERE

# Installation prefix
prefix=/usr/local/pgsql

# Data directory
PGDATA="/usr/local/pgsql/data"

# Who to run the postmaster as, usually "postgres". (NOT "root")
PGUSER=postgres

# Where to keep a log file
PGLOG="$PGDATA/serverlog"

## STOP EDITING HERE
# Check for echo -n vs echo \c
if echo '\c' | grep -s c >/dev/null 2>&1 ; then
ECHO_N="echo -n"
ECHO_C=""
else
ECHO_N="echo"
ECHO_C='\c'
fi

# The path that is to be used for the script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# What to use to start up the postmaster (we do NOT use pg_ctl for this,
# as it adds no value and can cause the postmaster to misrecognize a stale
# lock file)
DAEMON="$prefix/bin/postmaster"

# What to use to shut down the postmaster
PGCTL="$prefix/bin/pg_ctl"

set -e

# Only start if we can find the postmaster.
test -x $DAEMON || exit 0

# Parse command line parameters.
case $1 in
start)
$ECHO_N "Starting PostgreSQL: "$ECHO_C
su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
sleep 5
su - $PGUSER -c "PGPASSWORD=******** $prefix/bin/pg_autovacuum -D -s 500 -S 2 -U postgres"
echo "ok"
;;
stop)
echo -n "Stopping PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast"
echo "ok"
;;
restart)
echo -n "Restarting PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"
;;
reload)
echo -n "Reload PostgreSQL: "
su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
echo "ok"
;;
status)
su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
;;
*)
# Print help
echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
exit 1
;;
esac

exit 0
Back to top
View user's profile Send private message
swadams
Beginner


Joined: Aug 24, 2005
Posts: 12

PostPosted: Fri Aug 26, 2005 5:20 pm    Post subject: Reply with quote

I hadn't read it because the linked part looked so similar to the rest that I didn't realize it was linked. I thought you'd been distracted and forgotten to put in the link. If I came across as arrogant, I didn't mean to and I apologize.

Update: I did what that page said to do for SuSE and there's no difference.

Update 2: I showed it to the guy who installed SuSE and even he doesn't understand. He found no error messages in the logs concerning the script and sees no reason why the script isn't running at startup.
Back to top
View user's profile Send private message
jimmo
Administrator


Joined: Jul 27, 2002
Posts: 309
Location: Coburg, Germany

PostPosted: Sat Aug 27, 2005 7:09 am    Post subject: Reply with quote

Does this program exist at this exact location and is it executable?

/usr/local/pgsql/bin/postmaster

To be sure that there is no misunderstanding. I don't want to know if the "postmaster" program exists somewhere on this system. I want to know if it is in this [b]exact[/b] location.
Back to top
View user's profile Send private message
swadams
Beginner


Joined: Aug 24, 2005
Posts: 12

PostPosted: Sat Aug 27, 2005 8:56 pm    Post subject: Reply with quote

[quote="jimmo"]Does this program exist at this exact location and is it executable?

/usr/local/pgsql/bin/postmaster

To be sure that there is no misunderstanding. I don't want to know if the "postmaster" program exists somewhere on this system. I want to know if it is in this [b]exact[/b] location.[/quote]

Yes, that's exactly where it is. I checked it immediately before writing this just to be sure.

Oh, and ffreeloader, I never said the "Starting PostgreSQL" line prints at startup except on the Red Hat computer, where the script runs at startup. The guy who installed SuSE saw for himself that the script isn't running at startup on the SuSE computer and he doesn't understand why, either.
Back to top
View user's profile Send private message
swadams
Beginner


Joined: Aug 24, 2005
Posts: 12

PostPosted: Sun Aug 28, 2005 12:34 am    Post subject: Reply with quote

Thanks, Tripwire, for your input.
Back to top
View user's profile Send private message
jimmo
Administrator


Joined: Jul 27, 2002
Posts: 309
Location: Coburg, Germany

PostPosted: Sun Aug 28, 2005 7:06 am    Post subject: Reply with quote

[quote="swadams"]
Yes, that's exactly where it is. I checked it immediately before writing this just to be sure.

Oh, and ffreeloader, I never said the "Starting PostgreSQL" line prints at startup except on the Red Hat computer, where the script runs at startup. The guy who installed SuSE saw for himself that the script isn't running at startup on the SuSE computer and he doesn't understand why, either.[/quote]

One of the things that is frustrating to me and apparently to ffreeloader, as well, is that you still haven't said very much. At least, not until we pull it out of you.You still haven't answered ffreeloaders questions about /var/logs and dmesg. Except to say "PostgreSQL itself works fine".

The first post was simply to say the script doesn't work, but the permissions are correct. There are literally dozens of reasons why the script would not work, and you expect us to guess at what possibly could be wrong. As you noticed, people posted suggestions and you said "I already tried". Wouldn't it have been more efficient to have said that in the very first post? Instead, in an effort to help [b]you [/b] [i]for free[/i], several people have wasted their time suggesting things that you have tried, but did not bother to tell us. It only when we ask a specific question that you bother to tell us "I already tried that".

In all honesty, ffreeloader said what I was thinking. You have flat out ignored my suggestions. We are all doing this [b]for free[/b], and it is extremely annoying, when someone asks for help and expects [b]us[/b] to do all of the work and even more annoying when our suggestions are ignored.

I [b]know[/b], for a fact, after 20 years of working with UNIX, the kind of things I suggested will help because I have had to do it many times. On my machine at home, I still see the output when I start or stop the system because I have a "set -x" in my MySQL start script and I have just not bothered to remove it until now. It showed me exactly what the system was doing even though nothing was being displayed on the screen. If there is something in your script that causes it to exit early on, then the script [b]is[/b] being run, despite what you say. However, no one can prove this as you "refuse" to follow the suggestions that we make.

To be blunt, if you ignore what people are saying in an order to help you [b]for free[/b], then don't be surprised when people starting ignoring you.
Back to top
View user's profile Send private message
swadams
Beginner


Joined: Aug 24, 2005
Posts: 12

PostPosted: Sun Aug 28, 2005 4:50 pm    Post subject: Reply with quote

To jimmo:

I'm sorry if I seemed stubborn. I don't normally behave that way and the reason I did was that I thought you were trying to fix the wrong problem.

I did actually mention /var/log/messages and dmesg, but evidently not as clearly as I should have. Both the person who installed SuSE and I looked at them and we didn't find any errors concerning PostgreSQL or the script in question.

This problem isn't critical, just a nuisance, so I'm not going to use up any more of your time with it. Thanks anyway for your efforts. I'm not going to watch this thread anymore.
Back to top
View user's profile Send private message
marrylee
Newbie


Joined: May 13, 2011
Posts: 3

PostPosted: Fri May 13, 2011 7:16 am    Post subject: Reply with quote

I don't know what you're trying to start with the script, but it's also possible that you're trying to start it too early.....
_________________
saralin180@gmail.com
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Linux Tutorial Forum Index -> How To All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001-2007 phpBB Group
  
Show your Support for the Linux Tutorial

Purchase one of the products from our new online shop. For each product you purchase, the Linux Tutorial gets a portion of the proceeds to help keep us going.


Login
Nickname

Password

Security Code
Security Code
Type Security Code


Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!


Amazon Wish List

Did You Know?
You can choose larger fonts by selecting a different themes.


Friends



Tell a Friend About Us

Bookmark and Share



Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.23 Seconds