Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

start daemon when booting 2

Status
Not open for further replies.

peterve

IS-IT--Management
Mar 19, 2000
1,348
NL
Hi

2 short questions :

1. How can I start a program/daemon when booting my Linux server (Redhat 7.2) ?

2. How can I start a daemon/application when logging into the Linux server (locally, not from a ssh or telnet session) for eg. user x ?

Thanks






---------------------------------------------------------------------
I have not failed, I've just found 10,000 ways that don't work
---------------------------------------------------------------------
Peter Van Eeckhoutte
peter.ve@pandora.be
*:->* Did this post help? Click below to let me know !
 
1)You can start a process ,daemon or other, from the rc scripts or from inittab.

2) You can add a line starting the process in the users .profile, or a specialized script that is executed
from one of the users environment init scripts(which vary
by distribution) upon login.

sample:
prompt="string+%var"
exec /usr/sbin/popd -v && echo "Daemon started."
export prompt

 
Thanks

For starting the daemon during boot :
using inittab or rc scripts :
What is the exact syntax in those files ?

Starting the process in the users .profile :
The application is only allowed to start when logging on locally to the machine (so it is not allowed to work when logging on using ssh or telnet....) Is this possible ? ---------------------------------------------------------------------
I have not failed, I've just found 10,000 ways that don't work
---------------------------------------------------------------------
Peter Van Eeckhoutte
peter.ve@pandora.be
*:->* Did this post help? Click below to let me know !
 
Hi,

Almost all services on redhat (and most other linux systems) are started via the sysv init process. This requires a compliant script in /etc/rc.d/init.d and symbolic links to the script in the run-level directories, e.g. /etc/rc.d./init.d/rc3.d for run-level three.

Using run-level editor tools like chconfig, tksysv, ntsysv, you create links staring with a 'S' (start) or 'K' (kill) and a priority number. If you 'ls -l /etc/rc.d./init.d/rc3.d ' you will get the idea. Then when the run-level changes the relevant start or kill scripts are run for each service. For the services installed by redhat do :

/sbin/chkconfig --list (to see run-levels by service)
/sbin/chkconfig --level 345 httpd on (to turn on apache at run levels 3,4,5)

You can also use the mechanism to run your own scripts as long as they accept at least 'start' and 'stop' as arguments. Preferably, they should have the appropriate header line recognised by chkconfig (etc) that defines the default run-levels and priorities. To add you just do :

/sbin/chkconfig --add yourcode

There is, in fact, already a script in /etc/rc.d/init.d (local) that you can customise for your own purposes or use as a model.

The other, simpler, way is to add code (or call an external script file) to /etc/init.d/rc.local which is the last script run during the redhat boot-up process. This only runs at boot, however, not on change of run-level.

The second one might be a bit tricky because of permissions but you would just call it from the user's $HOME/.bash_profile file - e.g.

/etc/rc.d/init.d/httpd start
/etc/rc.d/init.d/httpd stop

or whatever.

For info on the various start-up files see -->
Hope this helps
 
How can I determine in which runlevel my application needs to run ?

Suppose the application is called Daemond, and it should be run in level3,

what are the exact steps I need to take to get it running...
(or at least point me to a website where I can find this information)

Thanks in advance ---------------------------------------------------------------------
I have not failed, I've just found 10,000 ways that don't work
---------------------------------------------------------------------
Peter Van Eeckhoutte
peter.ve@pandora.be
*:->* Did this post help? Click below to let me know !
 
Hi,

On redhat the run-levels are as follows :

0 — Halt

1 — Single-user mode

2 — Multi-user mode, without networking

3 — Full multi-user mode

4 — Not used

5 — Full multi-user mode (with an X-based
login screen)

6 — Reboot


So, you really only need to be concerned with runlevels 3 and 5 .

In you example, you'd create a script called /etc/rc.d/init.d/daemond and include a first comment line like :

# chkconfig: 35 20 80

This means run (start) at 3 & 5 with start priority 20 and kill priority 80.

You then add like this :

/sbin/chkconfig --add daemond

See the following for more info --> .

Regards
 
will /sbin/chkconfig --add daemond -B -v -i:3 work as well ?
(basicaly am I referring to the fact that I have to specify parameters)

Does my daemon has to support the start and stop command ? ---------------------------------------------------------------------
I have not failed, I've just found 10,000 ways that don't work
---------------------------------------------------------------------
Peter Van Eeckhoutte
peter.ve@pandora.be
*:->* Did this post help? Click below to let me know !
 
Hi,

Yes, to use the sysv init process the script would have to have start and stop. If you wanted to add parameters you'd have to read them from a config file within the script or make a special case in the underlying init script which rather defeats the object. What you would do is have two scripts - a sysv init 'cover' script and the one that takes the various parameters shown in your post. Your sysv script would just call the real script to start the service - something like /etc/rc.d/init.d/httpd .

See --> and any of the scripts in /etc/rc.d/init.d for more detailed examples.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top