即使没有真正的用户,如何在我的 Linux 服务中为 Asterisk 设置环境变量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3864877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I set environment variables in my Linux service for Asterisk even though it doesn't have a real user?
提问by domino
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.
我创建了一个作为守护进程运行的 linux 服务(并从 /etc/init.d/X 启动)。我需要设置一些应用程序可以访问的环境变量。
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/.bashrcbut that doesn't exist for asterisk.
这是场景。该应用程序是一堆 Perl AGI 脚本,它们依赖于(因此需要作为)asterisk 用户运行,但 asterisk 没有 shell。理想情况下,我只是将它设置在/home/asterisk/.bashrc 中,但对于星号来说不存在。
How can I set environment variables for my app in the asterisk user's running environment so that my app can use them?
如何在星号用户的运行环境中为我的应用设置环境变量,以便我的应用可以使用它们?
采纳答案by Fred Foo
Either set them in the startup script (/etc/init.d/yourdaemon
), or put a line in that file that looks like:
要么在启动脚本 ( /etc/init.d/yourdaemon
) 中设置它们,要么在该文件中放置一行,如下所示:
. /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.
并使用语法将环境变量放入该文件中export VAR=value
。在类似 Red Hat 的系统上,我相信这样一个文件的正确位置是/etc/sysconfig
. Debian/Ubuntu 似乎有/etc/default
这个目的。
回答by KCD
If your distro of choice is now using systemd try systemctl edit --full asterisk.service
and consider EnvironmentFile
and Environment
如果您选择的发行版现在正在使用 systemd,请尝试systemctl edit --full asterisk.service
考虑EnvironmentFile
并Environment
These files normally live here: /etc/systemd/system/myservice.service
e.g cron.service
这些文件通常位于此处:/etc/systemd/system/myservice.service
例如cron.service