Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing "env" directory #1

Open
mbuczko opened this issue Jul 22, 2015 · 5 comments
Open

missing "env" directory #1

mbuczko opened this issue Jul 22, 2015 · 5 comments

Comments

@mbuczko
Copy link

mbuczko commented Jul 22, 2015

for the following (generated) "run" command:

BASE_DIR=/opt/foo/bar
JAR=bar-1.0.0.jar
exec 2>&1
exec chpst -u root -e $BASE_DIR/env java -jar -server $BASE_DIR/$JAR

looks like missing "env" dir in $BASE_DIR prevents jar file from getting executed and log file is flooded with:

chpst: fatal: unable to switch to directory: /opt/foo/bar/env: file does not exist

would be nice to have "env" dir auto-created :)

@danielsz
Copy link
Owner

Hi,

env is not a directory, but a binary present on GNU/Linux systems that allows you to launch programs without having to hard-code their path.

@mbuczko
Copy link
Author

mbuczko commented Jul 23, 2015

that was also my first thought and I was surprised by the message about missing dir (btw. I'm running it within docker based on Ubuntu 14.04 where env as a binary obviously does exist).
anyway, I looked at the chpst man and it states clearly:

-e dir
    envdir. Set various environment variables as specified by files in the directory dir.

this is why

chpst -u root -e $BASE_DIR/env

treats $BASE_DIR/env as dir rather than binary file (or at least I guess so).

@danielsz
Copy link
Owner

I was totally wrong. I wasn't focused and missed the essence of your report. This also reminds me why I wrote boot-runit: so I won't need to remember the minutiae to setup runit every time .

So it goes like this: env is a directory where runit stores environment variables. If you type man chpst, you will notice the -e switch:

envdir. Set various environment variables as specified by files in the directory dir: If dir contains a file named k whose first line is v, chpst removes the environment variable k if it exists, and then adds the environment variable k with the value v. The name k must not contain =. Spaces and tabs at the end of v are removed, and nulls in v are changed to newlines. If the file k is empty (0 bytes long), chpst removes the environment variable k if it exists, without adding a new variable.

And this is how you invoke boot-runit in build-boot:

(deftask prod
  "deploy with runit"
  []
  (comp
   (build)
   (runit :env {:redis-instance "localhost"
                  :geoip-server "http://example.net:9090/json/"
                  :mongo-url "mongodb://example.com/example-db"})))

boot-runit will create the env directory for you according to that map. That is one of those things it does to alleviate the ceremony involved with runit.

And build, if you were wondering, is:

(deftask build
  "Builds an uberjar of this project that can be run with java -jar"
  []
  (comp
   (aot :namespace '#{example.main})
   (pom :project 'example
        :version "1.0.0")
   (uber)
   (jar :main 'example.main)))

Note: If your application doesn't use environment variables at all, you can try and manually remove the -e switch in run.

exec chpst -u root java -jar -server $BASE_DIR/$JAR

I hope this helps.

@mbuczko
Copy link
Author

mbuczko commented Jul 23, 2015

thanks for detailed answer. now, comming back to my initial idea wouldn't it be much easier and less confusing if the env dir was created by default (even if no :env's were provided) instead of modifying generated run? if it's a problem I may try to dig around and prepare some PR.

@danielsz
Copy link
Owner

All my apps use environment variables, so it didn't cross my mind, but sure, what you're proposing makes sense. A PR will be very welcome. Thank you.

Bonus points if you make it so that no -e switch appears in the run file when no environment variables are used. In that case, we don't need to create the env dir at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants