I use runit to daemonize my web application, and I'm trying to see if I can have my process managed by sv not have to have a corresponding envdir for its environment variables. I wonder if I can just pass those vars directly into my call to chpst. This is the run file under /etc/service/myapp:

exec 2>&1
cd /var/www/myapp
# what it currently looks like
exec chpst -u www-data:www-data /var/www/myapp/myapp
# what I'd ideally like to be able to do
FOO=bar BAZ=qux exec chpst -u www-data:www-data /var/www/myapp/myapp

As I mentioned, chpst also comes with a -e option to pass a directly with environment variables to it, I could use that, but I'm trying to avoid it for simplicity (fewer things to maintain). Is that at all possible? Tips?

  • I'm pretty sure you literally can do exactly what you wish to ideally be able to do. For example, FOO=bar exec printenv FOO in a #!/bin/sh - script should print "bar". If you have any shell where that doesn't work right I'd love to hear about it.
    – mtraceur
    Commented Jun 18, 2020 at 5:11

2 Answers 2


You can pass environments using the 'env' argument right before you invoke your app. I've done this for a single environment, though I'm not sure how one would provide multiple envariables

exec chpst -u www-data:www-data env LOGNAME='www-data' /var/www/myapp/myapp
  • 1
    For setting multiple environment variables when launching an application with env, just use env VAR1=value VAR2=value VAR3=value application.
    – Kusalananda
    Commented Aug 25, 2017 at 6:05
  • To be clear, env is not a special argument to chpst, it's a separate program. Both env and chpst are "exec chaining" programs - they change something about the process, and then execute the next program (the rest of their arguments) within the same process. So you could do env before chpst if you wanted, and more importantly, you can't have other options intended for chpst after the env argument to it.
    – mtraceur
    Commented Jun 18, 2020 at 5:05

You can just do:

FOO=bar BAZ=qux exec chpst -u www-data:www-data /var/www/myapp/myapp

If someone knows of a /bin/sh where this doesn't work I'd love to hear about it, but this line that you wished to be able to do would work exactly as you wished it to work on every shell I've tried it on.

You must log in to answer this question.

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