How can I set environment variables in my Linux service for Asterisk even though it doesn't have a real user?

廉价感情. 提交于 2019-12-19 12:50:29

问题


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?


回答1:


Either set them in the startup script (/etc/init.d/yourdaemon), or put a line in that file that looks like:

. /etc/yourdaemon.env

and put the environment variables in that file, using the syntax export VAR=value. On Red Hat-like systems, I believe the correct place for such a file is /etc/sysconfig. Debian/Ubuntu seems to have /etc/default for this purpose.




回答2:


If your distro of choice is now using systemd try systemctl edit --full asterisk.service and consider EnvironmentFile and Environment

These files normally live here: /etc/systemd/system/myservice.service e.g cron.service



来源:https://stackoverflow.com/questions/3864877/how-can-i-set-environment-variables-in-my-linux-service-for-asterisk-even-though

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!