linux - 如何在启动每个服务之前执行命令

标签 linux ubuntu coredump init.d sysctl

我想为/etc/init.d 中的每个服务设置安全限制说

ulimit -c unlimited

但这应该在发出“service <process> start”或“/etc/init.d/<process> start”时执行。

是否有一个通用路径,如果我们在那里写,它将应用于“启动”服务时的所有服务。

最佳答案

如果你创建一个像这样的文件:

/etc/init.d/.commonStuff

并在其中放入您希望对所有脚本通用的命令:(没有“#!/usr/bin/bash”行)

# This code is meant to be included by another script.
ulimit -c unlimited
umask 027
THIS_VARIABLE="will exist once the include is completed"
export THIS_VALIABLE    # And now it is exportable too

然后在每个脚本中你可以添加这些行(在一个方便的地方):

# Include the common settings
. /etc/init.d/.commonStuff

前导点是“包含一些其他文件”指示符。

确保新文件受到保护(即由 root 拥有),并从中删除可执行标志以明确它不是要单独执行的。 (访问不能超过644)。

关于linux - 如何在启动每个服务之前执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26480538/

相关文章:

docker - 如何使用 bsd-mailx 从 docker 容器发送电子邮件到主机 postfix?

bash - 如何为具有特定 ip 的打开浏览器创建 shell 脚本?

linux - 如果出现错误,gdb 将在命令文件中停止。尽管有错误如何继续?

c - 段错误(核心转储)错误 C linux 套接字

python - 如何在 bash 或 python 中检查 Ubuntu 程序 coredump?

linux - 在 Debian : could not find library containing RSA_new 上构建 Subversion 1.5.4

c - 简单的有线协议(protocol),一个人要做什么?

postgresql - pgadmin4 指定的用户不存在

linux - Entity Framework 7 是否适用于 Linux Dot Net Core CLR?

c - 在没有 LD_PRELOAD 的情况下在用户级别拦截系统调用