Bash – Setting environment variables for a service without a login shell on Debian

asteriskbashperl

I have created a linux service that runs as a deamon (and gets started from /etc/init.d/X). I need to set some environment variables that can be accessed by the application.

Here's the scenario. The application is a bunch of Perl AGI scripts that depend on (and therefore need to run as) asterisk user but asterisk doesn't have a shell. Ideally I'd just set this in /home/asterisk/.bashrc but that doesn't exist for asterisk.

How can I set environment variables for my app in the asterisk user's running environment so that my app can use them?

Update: Changed the title to show am using Debian.

Best Answer

Found the solution. For debian distro creating the file /etc/default/myservice and then adding the environment variables using the syntax export VAR=value

then sourcing the file from /etc/init.d/myservice using

[ -r /etc/default/myservice ] && . /etc/default/myservice solved the problem

Related Topic