Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Newbie
Reload this Page Automatically starting programs
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Newbie If you're new to the wonderful world of Linux, start here!

Reply
 
Thread Tools Display Modes
Old 04-16-2003   #1 (permalink)
Linux_Is_Cool
Just Joined!
 
Join Date: Apr 2003
Posts: 3
Automatically starting programs

Hi Everyone,

I am wondering how to go about automatically starting programs when my Red Hat (Version Linux distribution starts up. I need to know which file contains startup scripts and the format of startup commands. This is required because I want to start the Postmaster of PostgreSQL on bootup.

Also in addition to the above is it possible to set up Red Hat so that a particular program (in this instance PostgreSQL) only starts for a particular login identity?

Thanks for your assistance.

Regards

David
Linux_Is_Cool is offline   Reply With Quote
Old 04-17-2003   #2 (permalink)
Dolda2000
Linux Guru
 
Join Date: Oct 2001
Location: Täby, Sweden
Posts: 7,575
To run stuff on system startup, you use the SysV init scripts. Check out /etc/rc.d. You can add programs to the rc.local file, but that's quite crude, and PostgreSQL probably has an init script in init.d. You just need to create a link to it in rc3.d or rc5.d, whichever is your default runlevel.

To run programs when users log in, you must first decide which login manager to use. Do you want them to run when you start GNOME, KDE or when you just log in on a shell? In GNOME, check out the session manager preferences. I don't know about KDE, since I don't use it. In a login shell, add it to the user's .bash_profile script.
Dolda2000 is offline   Reply With Quote
Old 04-18-2003   #3 (permalink)
andutt
Linux Engineer
 
Join Date: Apr 2003
Location: Sweden
Posts: 796
In the Redhat distribution a cool program is included. chkconfig that program controlls every default start or stop program located under /etc/init.d and creating and removing symlinks in every runlevel directorys /etc/rc*.d. If your default runlevel is 3 (this you can find out by typing runlevel after bootup) type

chkconfig --list | grep 3n to find out which program/services that starts in runlevel 3.

To enable a program(mysql) in runlevel 3 type:

chkconfig --level 3 mysql on

The syntax is:

chkconfig --level 123456 <program> on|off

Read the manpage for this program to create your own start and stop scripts. With this program you dont have to go throw difficultis to create symlinks in every runlevel, which can take some time.

If you dont want to use this create your own start or stopscript and put it under /etc/init.d directory and create symlinks int the runlevel you want your program to start. You can also use /etc/rc.local file that are executed after all other services.

Enjoy!
__________________
Regards

Andutt
andutt is offline   Reply With Quote
Old 04-19-2003   #4 (permalink)
jasonlambert
Linux Guru
 
Join Date: Apr 2003
Location: London, UK
Posts: 3,284
use this script for PostGreSQL at boot time, follow the instructions in it:


Quote:
#! /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>

# $Header: /cvsroot/pgsql-server/contrib/start-scripts/linux,v 1.3 2001/07/30 14:52:42 momjian Exp $

## EDIT FROM HERE

# Installation prefix
prefix=/usr/local/pgsql

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

# Who to run pg_ctl as, should be "postgres".
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
DAEMON="$prefix/bin/pg_ctl"

set -e

# Only start if we can find pg_ctl.
test -f $DAEMON || exit 0

# Parse command line parameters.
case $1 in
start)
$ECHO_N "Starting PostgreSQL: "$ECHO_C
su - $PGUSER -c "$DAEMON start -D '$PGDATA' -s -l $PGLOG"
echo "ok"
;;
stop)
echo -n "Stopping PostgreSQL: "
su - $PGUSER -c "$DAEMON stop -D '$PGDATA' -s -m fast"
echo "ok"
;;
restart)
echo -n "Restarting PostgreSQL: "
su - $PGUSER -c "$DAEMON restart -D '$PGDATA' -s -m fast"
echo "ok"
;;
status)
su - $PGUSER -c "$DAEMON status -D '$PGDATA'"
;;
*)
# Print help
echo "Usage: $0 {start|stop|restart|status}" 1>&2
exit 1
;;
esac

exit 0

Jason
jasonlambert is offline   Reply With Quote
Old 05-08-2003   #5 (permalink)
_hyperion_
Just Joined!
 
Join Date: Apr 2003
Posts: 2
For PostgreSQL I would go through the normal SYSV startup scripts.

To see if you have the SYSV startup for postgres, try typing this from your prompt:

/etc/rc.d/init.d/postgresql start

If it starts up, then the SYSV script is in place. You just need to make a link to it from one of the run level areas (/etc/rc.d/rcX.d). Most likely you want to put it in the third run level, like /etc/rc.d/rc3.d/S90postgresql. But make that link to your /etc/rc.d/init.d/postgresql. This is how you do that:

ln -s /etc/rc.d/init.d/postgresql /etc/rc.d/rc3.d/S90postgresql.

Everything in your rcX.d dirs that starts with uppercase S will be run during startup (or when you change runlevels). And all the K files will be run with the STOP option to stop (kill) the processes. So you will also need to add a link to shut it down as well (to do it correctly).

If you just have a script that you write and you want to run it each time there is a quick and dirty way of doing it.
You can add something like this to your /etc/rc.d/rc.local file. This file is run after all other startup files.

Somethign like this would work for specifiying users:

if [ "$UID" = "500" ] ; then
/path/to/script/scripttorun
fi

Just put the correct userid in there. You might also be able to do it by name by using $USER. To check these, from the prompt (logged in as the user), type "echo $UID". Or check the /etc/passwd file for userids, just be careful in there - do not save it.

Don't forget to chmod 700 [scriptname] (at the very least) to make your script executable.

Anyway, hope this helps.

-John
_hyperion_ is offline   Reply With Quote
Old 05-10-2003   #6 (permalink)
turls
Just Joined!
 
Join Date: May 2003
Location: UK-Heart of Cheshire
Posts: 31
in redhat there is a gui option called SERVICES under the server setting option. THis can easily be used to configure what starts and what does not
turls is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 01:34 PM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0