文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Linux:systemctl管理开机自启进程

2023-10-25 07:07

关注

文件目录

# 查看目录文件ls /usr/lib/systemd/system/# 搜索ls /usr/lib/systemd/system | grep fpmphp-fpm.service

常用操作

# helpsystemctl -hsystemctl -l | grep fpmsystemctl list-unit-files | grep fpmphp-fpm.service   enabled# Unit File Commands# 开机时启动该服务systemctl enable php-fpm# 撤销开机启动systemctl disable php-fpm# Reenable one or more unit filessystemctl reenable php-fpm php-fpm-8.0.23# 验证一下是否为开机启动systemctl is-enabled php-fpm  # Unit Commands# Start (activate) one or more unitssystemctl start php-fpm# Show runtime status of one or more unitssystemctl status php-fpm# Reload one or more unitssystemctl reload php-fpm# Start or restart one or more unitssystemctl restart php-fpm# Send signal to processes of a unitsystemctl kill php-fpm# Stop (deactivate) one or more unitssystemctl stop php-fpm#显示全部已经启动的服务systemctl list-units --type=service# Reset failed state for all, one, or more unitssystemctl reset-failed

配置文件示例

PHP安装后生成的配置文件

/usr/lib/systemd/system/php-fpm-8.0.24.service

# It's not recommended to modify this file in-place, because it# will be overwritten during upgrades.  If you want to customize,# the best way is to use the "systemctl edit" command.[Unit]Description=The PHP FastCGI Process ManagerAfter=network.target[Service]Type=simplePIDFile=/usr/local/php/8.0.24/var/run/php-fpm.pidExecStart=/usr/local/php/8.0.24/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/8.0.24/etc/php-fpm.confExecReload=/bin/kill -USR2 $MAINPID# Set up a new file system namespace and mounts private /tmp and /var/tmp directories# so this service cannot access the global directories and other processes cannot# access this service's directories.PrivateTmp=true# Mounts the /usr, /boot, and /etc directories read-only for processes invoked by this unit.ProtectSystem=full# Sets up a new /dev namespace for the executed processes and only adds API pseudo devices# such as /dev/null, /dev/zero or /dev/random (as well as the pseudo TTY subsystem) to it,# but no physical devices such as /dev/sda.PrivateDevices=true# Explicit module loading will be denied. This allows to turn off module load and unload# operations on modular kernels. It is recommended to turn this on for most services that# do not need special file systems or extra kernel modules to work.ProtectKernelModules=true# Kernel variables accessible through /proc/sys, /sys, /proc/sysrq-trigger, /proc/latency_stats,# /proc/acpi, /proc/timer_stats, /proc/fs and /proc/irq will be made read-only to all processes# of the unit. Usually, tunable kernel variables should only be written at boot-time, with the# sysctl.d(5) mechanism. Almost no services need to write to these at runtime; it is hence# recommended to turn this on for most services.ProtectKernelTunables=true# The Linux Control Groups (cgroups(7)) hierarchies accessible through /sys/fs/cgroup will be# made read-only to all processes of the unit. Except for container managers no services should# require write access to the control groups hierarchies; it is hence recommended to turn this on# for most servicesProtectControlGroups=true# Any attempts to enable realtime scheduling in a process of the unit are refused.RestrictRealtime=true# Restricts the set of socket address families accessible to the processes of this unit.# Protects against vulnerabilities such as CVE-2016-8655RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX# Takes away the ability to create or manage any kind of namespaceRestrictNamespaces=true[Install]WantedBy=multi-user.target

Type:定义启动时的进程行为

参考
systemctl 详解

来源地址:https://blog.csdn.net/mouday/article/details/127700732

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-人工智能
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯