Linux设置服务或者程序和脚本开机启动
Posted 白-胖-子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux设置服务或者程序和脚本开机启动相关的知识,希望对你有一定的参考价值。
设定服务开机启动
设定某服务开机自启,相当于chkconfig name on
systemctl enable name.service
设定某服务开机禁止启动:相当于chkconfig name off
systemctl disable name.service
查看所有服务的开机自启状态,相当于chkconfig --list
systemctl list-unit-files --type service
用来列出该服务在哪些运行级别下启用和禁用:chkconfig –list name
ls /etc/systemd/system/*.wants/name.service
查看服务是否开机自启:
systemctl is-enabled name.service
列出失败的服务
systemctl --failed --type=service
开机并立即启动或停止
systemctl enable --now postfix
systemctl disable --now postfix
设定脚本或非独立程序
- 将脚本或者程序写进/etc/rc.local 文件
- /etc/rc.local 文件需要拥有执行权限(Ubuntu默认没有)
- 脚本或者程序需要拥有执行权限
ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 11月 8 2019 /etc/rc.local -> rc.d/rc.local
[02:32:47 root@C8-3-55 ~]#cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
以上是关于Linux设置服务或者程序和脚本开机启动的主要内容,如果未能解决你的问题,请参考以下文章