我如何在我的Linux服务中为Asterisk设置环境变量,即使它没有真正的用户?

时间:2021-01-11 15:38:46

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.

我创建了一个作为deamon运行的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/.bashrc but that doesn't exist for asterisk.

这是场景。应用程序是一堆Perl AGI脚本,这些脚本依赖于(因此需要作为)asterisk用户,但asterisk没有shell。理想情况下,我应该把它设为/home/asterisk/。但这对于星号来说是不存在的。

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

如何在asterisk用户的运行环境中设置应用程序的环境变量,以便应用程序使用?

1 个解决方案

#1


22  

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.

并使用语法导出VAR=值将环境变量放在该文件中。在红色的hata系统上,我认为这个文件的正确位置是/etc/sysconfig。Debian/Ubuntu在这方面似乎有/etc/default。

#1


22  

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.

并使用语法导出VAR=值将环境变量放在该文件中。在红色的hata系统上,我认为这个文件的正确位置是/etc/sysconfig。Debian/Ubuntu在这方面似乎有/etc/default。