Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Are there special requirements for invoking Java in a script controlled by launchd?



Mark Leone wrote:

>I'm still having daemon issues, but a different problem from what I posted
>in a recent thread. I have a shell script that invokes my java app, using
>
>java -cp my/classpath path/to/my/app

I think path/to/my/app should be pkg.of.my.App.  I realize the slashed form
works, it's just unconventional.

And I recommend NOT using a shell-script from an agent's plist file.  Just
enter the command-line args directly in your agent's plist file.  Otherwise
you have to think about controlling a shell that's controlling your app,
instead of just controlling your app.  Eliminate needless complication.


>The shell script is launched by launchd with user scope, by putting a plist
>file in ~/Library/LaunchAgents. The script and java app launch properly.
>However, my reason for using launchd is that I want to have the app running
>in the background but also give the user the capability to select an action
>that will stop it. But I can't get launchd to stop the java app, and I
>think it may be because of the way I'm invoking it in the script..

The short answer to the subject-line of your post is:
  Not that I know of.

Last year, I did a fair amount of experimenting with agents, daemons, etc.
in Java, all controlled by launchd, and never noticed that 'java' was any
different from any other commands that are suitable for agents or daemons.

That said, you haven't given enough information about what's in your
agent-plist to be able to tell what's going on.  Launchd daemons and agents
have an autonomous nature that can be hard to fathom, and it's not
something you can just hack around with and expect good results.


>From Terminal, I see the launchd item as expected via "launchctl list".
>And when I enter
>
>           launchctl stop the.process.id
>
>The command returns normally in Terminal, and in the Console I see a
>launchd message that the item terminated. The problem is the app is still
>running.

Read the fine man page for 'launchctl':
  stop joblabels ...
    ... Jobs may restart automatically if demand-driven.

If a job is demand-driven, you first have to get launchd to stop
interpreting the rules that control the launching of the job.  That is, you
have to tell launchd to un unload the agent's config-file, i.e. its plist
file.  Then you can stop the on-demand job without having it restarted by
launchd.

And the joblabel is *not* a "process.id".  Not even close.


>If I try
>
>          launchctl start the.process.id
>
>launchd reports that it's not running. If I start the daemon again via
>launchd, I get a second instance of the app running.

What do you mean by "start the daemon again via launchd"?  That doesn't
make any sense, because you don't start the daemon again, launchd does.
And launchd starts the daemon or agent when it wants, according to the
rules in the plist file.  In other words, if you told launchd your program
is to be launched on-demand, then that's what launchd will do: launch your
program on demand.

If you want launchd to do something else, you have to tell it what to do,
either by changing the plist config-file or some other indirect means.
There should be no direct launching of your app.  Only launchd should do
that, and if you've told it the correct launch rules, that should take care
of it.  If you HAVEN'T told launchd the correct rules, then you need to
figure that out and tell launchd.

Launchd is not a shell awaiting your commands.  It's an autonomous agent
supervising the launching of other programs.  You give it rules for how and
when to launch things, and it does its best to follow those rules.

You can't micromanage launchd.  It's an autonomous manager/supervisor, and
works under its own rules.  You have to give it the rules, which it then
follows.  If you attempt to do something that triggers a rule, launchd will
act on the rules you gave it.  If you want it to stop following those
rules, you have to unload the rules it's following.


>Is it because launchd is only controlling the script execution, but the
>Java app is running on its own? I thought that since I didn't use "exec
>java..." this wouldn't be the case.

If you refer directly to a java command in your plist file, you won't have
the problems that can arise when a shell is between launchd and the command
of interest.


>I have OnDemand set to "yes" in the plist file, and the plist file,
>script, and app are owned by the logged in user (permission = rwx), with
>group and other set to not writable, per the required configuration for
>launchd items as given in the apple documentation.

Please post the XML contents of your agent's plist file.  Please  post the
shell-file you're using, too.

  -- GG


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.