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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.