i want to start an application automatically at boot in unix : Please help urgent !!!

i want to start an application automatically at boot in unix : Please help urgent !!!

Post by indi » Sat, 06 Sep 2003 04:48:34



it is a news application which we start using the command "ant all" in
unix as root.

but what i really want to do is to check whether the application is
already running and if not start it automatically....i think it
involves a crontab entry..also i want to start it automatically at
boot.

any help will be greatly appreciated.

yours sincerely,

down_to_planet.

 
 
 

i want to start an application automatically at boot in unix : Please help urgent !!!

Post by tri.. » Sat, 06 Sep 2003 05:33:02



> it is a news application which we start using the command "ant all" in
> unix as root.
> but what i really want to do is to check whether the application is
> already running and if not start it automatically....i think it
> involves a crontab entry..also i want to start it automatically at
> boot.

you should try with rc.d scripts, which will be proably located in /etc/rc.d

create file called rc.ant, looking more or less like this:

#!/bin/sh
case "$1" in
   'start')
      if [ -f /var/run/ant.pid ]; then
        echo ant is already running
        exit 1
      else
        echo Starting ant: /usr/bin/ant all
        /usr/bin/ant all
        pidof ant > /var/run/ant.pid
     fi ;;
   'stop')
      if [ -f /var/run/ant.pid ]; then
        ANT_PID="`cat /var/run/ant.pid`"
        kill -TERM "$ANT_PID"
        rm /var/run/ant.pid
      else
        echo ant is not running
        exit 1
      fi ;;
   'restart')
      if [ -f /var/run/ant.pid ]; then
        ANT_PID="`cat /var/run/ant.pid`"
        kill -HUP "$EXIM_PID"
      else
        $0 start
      fi ;;
   *)
      echo "usage: $0 start|stop|restart" ;;
esac

above code is simplest skeleton, so may fail if something unexpected will happen.
you may extend it, or look at other scripts in /etc/rc.d/

when this script is ready, make it executable and add to other boot scripts.
depending on your unix version, you'll have to
a) add a line "/etc/rc.d/rc.ant start" to /etc/rc.d/rc.$RUNLEVEL (RUNLEVEL is 3, 4 or 5)
     and line "/etc/rc.d/rc.ant stop" to /etc/rc.d/rc.0 and /etc/rc.d/rc.6
(it looks like that on my slackware linux, i don't remember exact pathes and filenames
in other OSes, but i hope, someone other will tell something more...)

remember, when you decide to use such scripts, always start your news application
through /etc/rc.d/rc.ant start and stop it by using /etc/rc.d/rc.ant stop
state of your process will be indicated by file /var/run/ant.pid - when it will be
running, file will store PID of application's process, when no, file will be unlinked.

--
Jacek Pospychala - tri10o at bsod dot org

 
 
 

i want to start an application automatically at boot in unix : Please help urgent !!!

Post by Alan Conno » Sat, 06 Sep 2003 05:57:16



Quote:

> it is a news application which we start using the command "ant all" in
> unix as root.

> but what i really want to do is to check whether the application is
> already running and if not start it automatically....i think it
> involves a crontab entry..also i want to start it automatically at
> boot.

> any help will be greatly appreciated.

> yours sincerely,

> down_to_planet.

I can tell you how it's done in Debian linux:

There is a directory called /etc/init.d  that contains all of the scripts
that run at boot time. You'd put your script there.

Then there is another directory in /etc that is named rcS.d.

In that you would put a symlink to your script in ../init.d  that was
suffixed by an S and followed by a number from 1-100 that would assign
the script's place in the boottime lineup.


ls -l lrwxrwxrwx    1 root     root           20 Apr 14  2002 S30checkfs.sh -> ../init.d/checkfs.sh*

HTH

Alan C

--

   take control of your mailbox ----- elrav1 ----- http://tinyurl.com/l55a

 
 
 

i want to start an application automatically at boot in unix : Please help urgent !!!

Post by Cameron Lai » Sat, 06 Sep 2003 07:27:37





>> it is a news application which we start using the command "ant all" in
>> unix as root.

>> but what i really want to do is to check whether the application is
>> already running and if not start it automatically....i think it
>> involves a crontab entry..also i want to start it automatically at
>> boot.

                        .
                        .
                        .
Quote:>There is a directory called /etc/init.d  that contains all of the scripts
>that run at boot time. You'd put your script there.

                        .
                        .
                        .
It's more than that--and the difference is what's missing
from Mr. Pospychala's suggestion elsewhere in this thread:
init not only launches applications at boot time, but re-
starts during normal operations instances that happen to
have died (approximately).  You definitely want to study
`man init`.
--


Business:  http://www.Phaseit.net
Personal:  http://phaseit.net/claird/home.html

 
 
 

i want to start an application automatically at boot in unix : Please help urgent !!!

Post by Alan Conno » Sat, 06 Sep 2003 09:31:40






>>> it is a news application which we start using the command "ant all" in
>>> unix as root.

>>> but what i really want to do is to check whether the application is
>>> already running and if not start it automatically....i think it
>>> involves a crontab entry..also i want to start it automatically at
>>> boot.
>                    .
>                    .
>                    .
>>There is a directory called /etc/init.d  that contains all of the scripts
>>that run at boot time. You'd put your script there.
>                    .
>                    .
>                    .
> It's more than that--

Yes, there is more than that. You snipped the second half of my post.

and the difference is what's missing

Quote:> from Mr. Pospychala's suggestion elsewhere in this thread:
> init not only launches applications at boot time, but re-
> starts during normal operations instances that happen to
> have died (approximately).  

Which is EXACTLY what the OP says he wants.

What I told him works perfectly and I KNOW it does because I do it that way
myself.

Perhaps, since you are so very knowledgable, you could like give the OP
the answer he needs?

Just a thought.

Alan C

--

   take control of your mailbox ----- elrav1 ----- http://tinyurl.com/l55a

 
 
 

i want to start an application automatically at boot in unix : Please help urgent !!!

Post by j.. » Sat, 06 Sep 2003 11:11:53



> it is a news application which we start using the command "ant all"
> in unix as root.

> but what i really want to do is to check whether the application is
> already running and if not start it automatically....i think it
> involves a crontab entry..also i want to start it automatically at
> boot.

Cameron's suggestion is probably correct, if I understand what you
want. Don't be confused by the similarity between init and
/etc/init.d, stuff under /etc/init.d only gets run once at boot time
(unless you manually run it again). If you enter something in
/etc/inittab, you can have the system restart it if it dies.

As Cameron suggested, read the man pages about init on your
system, as all systems don't use exactly the same setup. It doesn't
sound like crontab is the right tool for this job.

Joe

 
 
 

i want to start an application automatically at boot in unix : Please help urgent !!!

Post by Alan Conno » Sat, 06 Sep 2003 13:34:21






>>> it is a news application which we start using the command "ant all" in
>>> unix as root.

>>> but what i really want to do is to check whether the application is
>>> already running and if not start it automatically....i think it
>>> involves a crontab entry..also i want to start it automatically at
>>> boot.
>                    .
>                    .
>                    .
>>There is a directory called /etc/init.d  that contains all of the scripts
>>that run at boot time. You'd put your script there.
>                    .
>                    .
>                    .
> It's more than that--and the difference is what's missing
> from Mr. Pospychala's suggestion elsewhere in this thread:
> init not only launches applications at boot time, but re-
> starts during normal operations instances that happen to
> have died (approximately).  You definitely want to study
> `man init`.

Well Cameron, I've been reading in man init, and you are very right about
the big picture being more complex than I made it seem in my post.

Never-the-less, I have been using that "recipe" for quite a while, and it
seems to work fine. Perhaps as I read further I will pick up some refinements.

Thanks,

Alan C

--

   take control of your mailbox ----- elrav1 ----- http://tinyurl.com/l55a

 
 
 

i want to start an application automatically at boot in unix : Please help urgent !!!

Post by Duc Hoa » Sat, 06 Sep 2003 22:54:24


Using rc script will allow you to start and stop the process when
needed but the setup will be more detailed. Another way to start your
command at boot time is to put it in /etc/inittab. I'm quite sure
there is actually one in your system. Anyway syntax for the line to be
added is :

id:rstate:action:process
i.e. in your case
ant:234:respawn:ant all

ant is just a label. 2,3 and 4 are the different init multi-user
state. Respawn is to restart when the process dies. For the process to
be executed, give the full name (path included). You can read "man
inittab" if you have one on your system.

Duc Hoang



> > it is a news application which we start using the command "ant all"
> > in unix as root.

> > but what i really want to do is to check whether the application is
> > already running and if not start it automatically....i think it
> > involves a crontab entry..also i want to start it automatically at
> > boot.

> Cameron's suggestion is probably correct, if I understand what you
> want. Don't be confused by the similarity between init and
> /etc/init.d, stuff under /etc/init.d only gets run once at boot time
> (unless you manually run it again). If you enter something in
> /etc/inittab, you can have the system restart it if it dies.

> As Cameron suggested, read the man pages about init on your
> system, as all systems don't use exactly the same setup. It doesn't
> sound like crontab is the right tool for this job.

> Joe

 
 
 

i want to start an application automatically at boot in unix : Please help urgent !!!

Post by William Aher » Sun, 07 Sep 2003 02:24:27




>> it is a news application which we start using the command "ant all" in
>> unix as root.
>> but what i really want to do is to check whether the application is
>> already running and if not start it automatically....i think it
>> involves a crontab entry..also i want to start it automatically at
>> boot.

> you should try with rc.d scripts, which will be proably located in /etc/rc.d

> create file called rc.ant, looking more or less like this:

> #!/bin/sh
> case "$1" in
>    'start')
>       if [ -f /var/run/ant.pid ]; then
>         echo ant is already running
>         exit 1
>       else
>         echo Starting ant: /usr/bin/ant all
>         /usr/bin/ant all
>    pidof ant > /var/run/ant.pid
>      fi ;;

wouldn't it be safer to do:

        /usr/bin/ant all &
        echo $! > /var/run/ant.pid

in any event, on openbsd there is no pidof(1).

 
 
 

i want to start an application automatically at boot in unix : Please help urgent !!!

Post by tri.. » Sun, 07 Sep 2003 22:47:20



>> create file called rc.ant, looking more or less like this:

>> #!/bin/sh
>> case "$1" in
>>    'start')
>>       if [ -f /var/run/ant.pid ]; then
>>         echo ant is already running
>>         exit 1
>>       else
>>         echo Starting ant: /usr/bin/ant all
>>         /usr/bin/ant all
>>       pidof ant > /var/run/ant.pid
>>      fi ;;

> wouldn't it be safer to do:

>        /usr/bin/ant all &
>        echo $! > /var/run/ant.pid

you're right, but it's still not enough. it is always possible, that
ant all will exit with some error, but PID will be piped into ant.pid,
not ensuring, that ant all is really running.

the same problem is with "stop", so the lines:

        kill -TERM "$ANT_PID"
        rm /var/run/ant.pid

should better be changed to:

        if  kill -TERM "$ANT_PID"; then
                rm /var/run/ant.pid;
        else
                echo ant dont want to stop. kill it by yourself...
                exit 1
        fi

Quote:> in any event, on openbsd there is no pidof(1).

currently i'm *bsd ignorant but gonna change it -
- before going to university:) (i have last 3 weeks...)
but thanks for info

--
Jacek Pospychala - tri10o at bsod dot org