12

I need to daemonize a Windows app running in Wine, and create a pid in /var/run. Since it requires an X11 session to run, I need to make sure the $DISPLAY variable is set in the running user's environment.

Assuming I already have a X11 session running, with a given display, here's what the start-stop-daemon line looks like in my /etc/init.d script:

start-stop-daemon --start --pidfile /var/run/wine-app.pid -m -c myuser -g mygroup -k 002 --exec /home/myuser/.wine/drive_c/Program\ Files/wine-app.exe

Unfortunately, my version of start-stop-daemon on Ubuntu 8.04 doesn't have the -e option to set environmental variables. I gather that you could simply set $DISPLAY before the command, like so:

VAR1="Value" start-stop-daemon ...

But it doesn't work. Since I'm using the -c {user} option to run as a specific user, I'm guessing there's an environment switch and VAR1 is lost. I've tried exporting DISPLAY from the running user's .profile and/or .bashrc but it doesn't work either.

Is there another way to do this? Is this even possible? Am I overlooking something?

Paul T.
  • 119
  • 6
scottburton11
  • 123
  • 1
  • 1
  • 5

3 Answers3

23

You can use env to modify the environment:

start-stop-daemon --start --pidfile /var/run/wine-app.pid -m -c myuser -g mygroup -k 002 --exec /usr/bin/env VAR1="Value" /home/myuser/.wine/drive_c/Program\ Files/wine-app.exe
Oli
  • 1,791
  • 17
  • 27
Jakob
  • 231
  • 2
  • 2
3

You could write a shell script to set the variable and then run wine.

Teddy
  • 5,134
  • 1
  • 22
  • 27
  • Haven't had the chance to put this in to practice, but I wrote the script and it seems like the best way to go. Thanks for the tip! – scottburton11 Apr 09 '10 at 21:07
1

The Gentoo version of start-stop-daemon utility has an -e/--env option:

start-stop-daemon --start --pidfile /var/run/wine-app.pid -m \
    -c myuser -g mygroup -k 002 -e VAR1="Value" -e VAR2="Other value" \
    --exec /home/myuser/.wine/drive_c/Program\ Files/wine-app.exe
Cyber Tailor
  • 111
  • 2
  • Welcome! This answer is OK for general reference, but the OP mentions that "my version of start-stop-daemon on Ubuntu 8.04 doesn't have the -e option" – TylerW Feb 23 '22 at 16:52