3

My app is a jar file that requires some environment variables. I have all the environment variables in one file, which looks like this:

export VAR=value
export VAR2=value2
#....etc

My supervisor config file looks like this:

[program:programname]
command=bash -c "source /path/to/env/file && java -jar /path/to/jar.jar"

ps -ef | grep programname shows two processes on two separate lines: one is bash -c "source blah && java blah" and the other one is just java blah.

Now, here's the problem: whether I do supervisorctl stop programname or service supervisor stop or even kill -9 whatever the supervisor pid is, the first process dies, but the regular java process stays and becomes orphaned, with parent pid now 1. How do I make the jar die without manually killing it?

1
  • 1
    Try adding killasgroup=true. (and stopasgroup=true if you wish). Jun 3, 2016 at 15:26

2 Answers 2

3

Use exec to replace bash with java:

[program:programname]
command=bash -c "source /path/to/env/file && exec java -jar /path/to/jar.jar"

In such a case you will have only one process to kill.

1
  • This works too, and requires less changes than the other comment. Granted if I kill -9 the supervisor daemon itself it still leaves the jar running, but that's just what happens when you murder a process like that with no warning.
    – snetch
    Jun 3, 2016 at 16:16
2

Make the command instead a shell script that replaces itself with the java?

#!/bin/bash
source /i/pity/da/env/foo
exec java ...
1
  • It's working! I'll wait for a day or two before accepting, though, since this is the first answer.
    – snetch
    Jun 3, 2016 at 15:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .