Loading ...
Sorry, an error occurred while loading the content.

Starting a Java program from rc.local

Expand Messages
  • Chad Martin
    I have a little Java server app that I want to start at boot. I have the classpath set in /etc/profile such that I can run java serverApp & and it ll go
    Message 1 of 5 , Jul 3, 2003
    • 0 Attachment
      I have a little Java server app that I want to start at boot. I have
      the classpath set in /etc/profile such that I can run

      java serverApp &

      and it'll go nicely. However, it doesn't seem to like to do this when
      called from rc.local. I poked around on the web, and one person said to
      make sure to run it in the background, and another person said to set
      the classpath earlier in rc.local. Neither thing seems to work.
      Anybody get something like this going and know what I'm doing wrong?

      Thanks,
      Chad Martin
    • Bob Young
      On Thu, 03 Jul 2003 10:10:05 -0500 ... When rc.local is run at boot time no environment has been set, and therefore the PATH variable is empty. To run an
      Message 2 of 5 , Jul 3, 2003
      • 0 Attachment
        On Thu, 03 Jul 2003 10:10:05 -0500
        Chad Martin <chad@...> wrote:

        > I have a little Java server app that I want to start at boot. I have
        > the classpath set in /etc/profile such that I can run
        >
        > java serverApp &
        >
        > and it'll go nicely. However, it doesn't seem to like to do this when
        > called from rc.local. I poked around on the web, and one person said to
        > make sure to run it in the background, and another person said to set
        > the classpath earlier in rc.local. Neither thing seems to work.
        > Anybody get something like this going and know what I'm doing wrong?

        When rc.local is run at boot time no environment has been set, and therefore
        the PATH variable is empty. To run an application from there, you need to
        provide full paths. Try specifying the full path to the java executable (e.g.
        /usr/lib/j2re1.4.0_01/bin/java) and also to your serverApp file.

        HTH
        Bob Young
      • Chad Martin
        ... Hm. I didn t expect that was the case, since the last line in the stock rc.local reads: touch /var/lock/subsys/local wouldn t /bin need to be in the path
        Message 3 of 5 , Jul 3, 2003
        • 0 Attachment
          Bob Young wrote:
          >>I have a little Java server app that I want to start at boot. I have
          >>the classpath set in /etc/profile such that I can run
          >>
          >>java serverApp &
          >>
          >>and it'll go nicely. However, it doesn't seem to like to do this when
          >>called from rc.local. I poked around on the web, and one person said to
          >>make sure to run it in the background, and another person said to set
          >>the classpath earlier in rc.local. Neither thing seems to work.
          >>Anybody get something like this going and know what I'm doing wrong?
          >
          > When rc.local is run at boot time no environment has been set, and therefore
          > the PATH variable is empty. To run an application from there, you need to
          > provide full paths. Try specifying the full path to the java executable (e.g.
          > /usr/lib/j2re1.4.0_01/bin/java) and also to your serverApp file.

          Hm. I didn't expect that was the case, since the last line in the stock
          rc.local reads:

          touch /var/lock/subsys/local

          wouldn't /bin need to be in the path for this to work?

          In any case, I tried to specify it with the full path to the java app,
          but that didn't work (i.e. java /path/to/serverApp &). I'll try putting
          the full path to my java executable and see what happens.

          Chad
        • Bob Young
          On Thu, 03 Jul 2003 11:12:10 -0500 ... Sorry - I may have misled you a little. Depending on which distribution you are running, there probably is a PATH set
          Message 4 of 5 , Jul 3, 2003
          • 0 Attachment
            On Thu, 03 Jul 2003 11:12:10 -0500
            Chad Martin <chad@...> wrote:

            > Hm. I didn't expect that was the case, since the last line in the stock
            > rc.local reads:
            >
            > touch /var/lock/subsys/local
            >
            > wouldn't /bin need to be in the path for this to work?

            Sorry - I may have misled you a little. Depending on which distribution you
            are running, there probably is a PATH set already, but it will include only
            standard directories containing administrative programs. For instance, my
            Slackware rc.S file contains the following line:
            PATH=/sbin:/usr/sbin:/bin:/usr/bin
            So /bin/touch would be redundant, since /bin is in the PATH, but that won't
            help with java, nor with user-installed stuff in places like /usr/local.
            Generally it is a good idea to use full paths in all additions to init scripts
            to avoid problems, and it certainly cannot hurt anything.

            Bob Young
          • Chad Martin
            ... Here s the fix, all you archive trollers: Java doesn t like full paths to programs, so you need to cd into the appropriate directory before running java.
            Message 5 of 5 , Jul 3, 2003
            • 0 Attachment
              Bob Young wrote:
              > Sorry - I may have misled you a little. Depending on which distribution you
              > are running, there probably is a PATH set already, but it will include only
              > standard directories containing administrative programs. For instance, my
              > Slackware rc.S file contains the following line:
              > PATH=/sbin:/usr/sbin:/bin:/usr/bin
              > So /bin/touch would be redundant, since /bin is in the PATH, but that won't
              > help with java, nor with user-installed stuff in places like /usr/local.
              > Generally it is a good idea to use full paths in all additions to init scripts
              > to avoid problems, and it certainly cannot hurt anything.

              Here's the fix, all you archive trollers:

              Java doesn't like full paths to programs, so you need to cd into the
              appropriate directory before running java. Here's the line I have in my
              rc.local:

              cd /path/to/program; /usr/java/j2sdk1.4.0_01/bin/java serverApp &

              I've seen it stressed that you should run the program in the background
              if it's some kind of server that you plan on running indefinitely, hence
              the &. This is on a Redhat 7.1 box.

              Thanks for the tip, Bob.

              Chad
            Your message has been successfully submitted and would be delivered to recipients shortly.