creating an init script

zelos zelos at wanadoo.fr
Fri Sep 30 07:01:22 UTC 2005


Michael,
Many thanks for your help. The script works now pretty well because of your advice.
I now have to improve it a little bit.

Many thanks,
Zelos





> Message du 28/09/05 11:40
> De : "Michael Velez" 
> A : zelos at wanadoo.fr, "'General Red Hat Linux discussion list'" 
> Copie à : 
> Objet : RE: creating an init script
> 
> -----Original Message-----
> 
> Hi everybody!
> 
> Currently using a Red Hat 7.2 server, I have to launch an application every
> startup as a normal, unprivilegied user...
> I remember Mandrake and the /etc/init.d/skeleton file which was an example
> for writing init script of your own. Unfortunately, I don't know how to
> create my own init script under Red Hat.
> More explanations:
> 1° log as user "toto"
> 2° launch a binary file "start_myapplication"
> 3° before rebooting, kill the application via "stop_myapplication", not the
> kill command!!!
> As you can see, I don't want to launch those as ROOT, for security reasons.
> I think I can launch the process as "toto" user in the script but don't
> exactly remember howto...
> 
> Any idea?
> 
> Many thanks,
> Zelos
> ---------------------
> 
> Zelos,
> 
> Something like the below should work.
> 
> I need to say several things:
> 
> - Study this script and make sure you know exactly what it's doing before
> putting it into operation (look up things in the man pages if necessary). In
> addition, I did not test this script, I just quickly wrote it in this e-mail
> (so there may be some typos although it looks ok). You may also need to
> change things in the logic to suit your needs.
> 
> - the chkconfig line (line 3) is useful for using the chkconfig tool. Add
> this script to the /etc/init.d directory (let's call it 'foo') and then run:
> 
> chkconfig --add foo
> 
> this command will create a S99foo file in rc2.d, rc3.d, rc4.d, and rc5.d
> (change the numbers if you want to start the command in different run
> levels) to start the script and create a K01foo file in rc0.d, rc1.d, and
> rc6.d to kill the script. Look at the chkconfig man page for further info.
> 
> - the start section creates a file called myapplication. This file is
> necessary for RedHat Enterprise Linux (which I use). I'm not sure about
> your version. In RHEL, you need this file because, before stopping
> myapplication, the general rc script will check to see whether it exists.
> If it doesn't, it won't even call 'foo stop' because it'll assume 'foo
> start' never ran, and your application won't get properly stopped.
> Likewise, the stop section deletes that file. Your OS may put these subsys
> files in a different directory if they exist at all. You need to check this
> out.
> 
> Hope this helps,
> Michael
> 
> 
> --- START OF SCRIPT ---
> #!/bin/bash
> #
> # chkconfig 2345 99 01
> # description: this scripts starts and stops myapplication
> #
> 
> start()
> {
> su - toto -c=start_myapplication
> touch /var/lock/subsys/myapplication
> }
> 
> stop()
> {
> su - toto -c=stop_myapplication
> rm -f /var/lock/subsys/myapplication
> }
> 
> case "$1" in
> start)
> start
> ;;
> stop)
> stop
> ;;
> restart)
> stop
> start
> ;;
> *)
> echo "Usage: $0 {start|stop|restart}"
> esac
> 
> --- END OF SCRIPT ---
> 
> ---------------------------------------------------------------------------------------
> Wanadoo vous informe que cet e-mail a ete controle par l'anti-virus mail.
> Aucun virus connu a ce jour par nos services n'a ete detecte.
> 
> 
> 
>





More information about the redhat-list mailing list