添加到 Linux 中的 $PATH 以便守护进程可以使用它

发布于 2024-09-12 16:59:50 字数 77 浏览 5 评论 0原文

我可以在哪里添加 $PATH 以便所有守护进程都可以使用它?那么它在守护进程启动之前就被“包含”或“来源”了吗?

非常感谢!

Where can I add to a $PATH so that it's available to all daemons? So that it's "included" or "sourced" before daemons start?

Many thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

述情 2024-09-19 16:59:50

一种选择是/etc/profile

One option would be /etc/profile.

韵柒 2024-09-19 16:59:50

我可能误读了,如果你想在守护进程之前运行一些东西,你可以创建一个 cron 作业或者...

系统启动文件位于 /etc/rc2.d 中。您可以将包含要在系统启动时运行的命令的文件添加到此目录。假设你想在系统启动时删除一些临时文件,你可以在 /etc/rc2.d 中放置一个名为 TempFileDel 的文件,其中包含删除临时文件的命令,这样它就会在每次系统重新启动时运行。

你好。
正如 shereenmotor 所说,通常启动脚本位于 /etc/rc2.d 中,但这取决于您运行的 UNIX/Linux 以及系统的默认运行级别。
但恐怕没那么容易。脚本名称必须遵循一些规则:
- 有两种脚本,比方说:终止脚本和启动脚本。两者都存储在/etc/rcX.d中。
- 首先执行终止脚本,然后执行启动脚本。
- 终止脚本名称必须以“K”开头。
- 起始脚本名称必须以“S”开头。
- 第一个字母后面必须有一个两位数的数字。这让“rc”知道脚本的执行顺序。 rc 是调用其他脚本的“主”脚本。查看您的 /etc/inittab.conf。
- 最后,你选择的名字。

当“rc”调用此脚本时,它会添加一个参数:“S”脚本启动,“K”脚本停止。这允许您对这两个操作使用相同的脚本,只需使用链接即可。

创建一个文件
<代码>

#!/bin/ksh
case $1 in
start)
   echo Removing file...
   rm /tmp/somefile;;
stop)
   echo bye!;;
esac

然后

ln -s /path/to/TempFileDel /etc/rc2.d/S10TempFileDel
ln -s /path/to/TempFileDel /etc/rc2.d/K10TempFileDel

I may have misread that, if you want to run something before daemons you could create a cron job or...

The system startup files are located in /etc/rc2.d. You can add a file to this directory with the commands you want to run at system startup. Suppose you want to delete some temp files at system startup, you could put a file named TempFileDel in your /etc/rc2.d with the commands to delete your temporary files, so it'll run every time system reboots.

Helo.
As shereenmotor says, usually, startup scripts are located in /etc/rc2.d, but this depends on the UNIX/Linux you run and your system's default run level.
But I'm afraid it's not that easy. The script name must follow some rules:
- There are two kind of scripts, let's say: kill scripts and start scripts. Both stored in /etc/rcX.d.
- kill scripts are executed first, after that start scripts.
- kill scripts name must start with a "K".
- start sctipts name must start with a "S".
- Following the first letter, there must be a two digit number. This lets "rc" know the order for the execution of the sctrips. rc is the "master" script which calls the others. Have a look at your /etc/inittab.
- Finally, a name of your choice.

when "rc" calls this scripts it adds a parameter: start for "S" scripts and stop for "K" scripts. This allows you to use the same script for both operations, just using links.

create a file

#!/bin/ksh
case $1 in
start)
   echo Removing file...
   rm /tmp/somefile;;
stop)
   echo bye!;;
esac

and then

ln -s /path/to/TempFileDel /etc/rc2.d/S10TempFileDel
ln -s /path/to/TempFileDel /etc/rc2.d/K10TempFileDel

空气里的味道 2024-09-19 16:59:50

在不同类型的 UNIX 上,守护进程有多种不同的启动方式。他们中的大多数都有一种设置环境的方法。

也许最基本的是为init进程设置环境,通常是通过/etc/inittab。这将为系统中的所有进程设置启动环境。

Daemons are started many different ways on different varieties of UNIX. Most of them have a way to setup the environment.

Perhaps the most fundamental is to set the environment for the init process, often through /etc/inittab. This will set the starting environment for all processes in the system.

和影子一齐双人舞 2024-09-19 16:59:50

如果您有脚本或命令,您可以将其放入 /bin/ 并使用 chmod 和 chown 设置适当的所有者和权限

If you have a script or a command, you could put it in /bin/ and set the appropiate owner and permisions using chmod and chown

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文