systemd设置rc.local开机启动

systemd 里有 rc-local.service ,只需要再写一个 rc.local 的脚本即可。

1、编辑 /usr/lib/systemd/system/rc-local.service 文件:

[Unit]

Description=/etc/rc.d/rc.local Compatibility

After=network.target

[Service]

Type=forking

ExecStart=/etc/rc.d/rc.local start

TimeoutSec=0

RemainAfterExit=yes

SysVStartPriority=99

[Install]

WantedBy=multi-user.target

其中 Install 那部分是自己写的,multi-user.target 代表3级别,graphical.target 代表5级别。

2、编辑 /etc/rc.d/rc.local 文件:

# cat /etc/rc.d/rc.local

#!/bin/bash

xxxxxxxxxx 代表自定义内容,设置开机启动

3、给 /etc/rc.d/rc.local 可执行权限:

#chmod +x /etc/rc.d/rc.local

4、开启 rc-local.service 服务:

#systemctl   enable   rc-local.service

#systemctl   --system  daemon-reload

#systemctl   start  rc-local.service

时间: 2024-12-20 12:09:08

systemd设置rc.local开机启动的相关文章

Ubuntu 16.04设置rc.local开机启动命令/脚本的方法(通过update-rc.d管理Ubuntu开机启动程序/服务)

注意:rc.local脚本里面启动的用户默认为root权限. 一.rc.local脚本 rc.local脚本是一个Ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令.该脚本位于/etc/路径下,需要root权限才能修改. 该脚本具体格式如下: #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the scrip

Debian 9.x "stretch" 解决 /etc/rc.local 开机启动问题

由于某些软件并没有增加开启启动的服务,很多时候需要手工添加,一般我们都是推荐添加命令到 /etc/rc.local 文件,但是 Debian 9 默认不带 /etc/rc.local 文件,而 rc.local 服务却还是自带的 [email protected] ~ # cat /lib/systemd/system/rc.local.service # This file is part of systemd. # # systemd is free software; you can re

编译安装Nginx //设置nginx自动开机启动

Nginx 安装 系统平台:CentOS release 6.6 (Final) 64位. 设置nginx 自动开机启动 :chkconfig --level 235 nginx on chkconfig 提供了一个维护/etc/rc[0~6] d 文件夹的命令行工具,它减轻了系统直接管理这些文件夹中的符号连接的负担.chkconfig主要包括5个原始功能:为系统管理增加新的服务.为系统管理移除服务.列出单签服务的启动信息.改变服务的启动信息和检查特殊服务的启动状态.当单独运行chkconfig

设置自己的开机启动服务

在CentOS系统下,主要有两种方法设置自己安装的程序开机启动.1.把启动程序的命令添加到/etc/rc.d/rc.local文件中,比如下面的是设置开机启动httpd. 1 #!/bin/sh 2 # 3 # This script will be executed *after* all the other init scripts. 4 # You can put your own initialization stuff in here if you don't 5 # want to

设置Raspberry Pi开机启动

树莓派程序开机启动设置. 关于开机启动,我在网上找的一个教程,然后照着做了一次. 需要开机启动的程序是自己写的 我的是一个数据传输的程序,名字为 trans.py 开机启动脚本,保存在/etc/init.d目录下面: #!/bin/bash # /etc/init.d/trans ### BEGIN INIT INFO # Provides: xiaofeng # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $sy

CentOS7 rc.local开机开法启动

CentOS 7添加开机启动服务/脚本 一.添加开机自启服务 在CentOS 7中添加开机自启服务非常方便,只需要两条命令(以Jenkins为例):systemctl enable jenkins.service #设置jenkins服务为自启动服务sysstemctl start  jenkins.service #启动jenkins服务 二.添加开机自启脚本 在centos7中增加脚本有两种常用的方法,以脚本autostart.sh为例:#!/bin/bash#description:开机自

Linux中 设置apache,mysql 开机启动

linux开启启动的程序一般放在/etc/rc.d/init.d/里面,/etc/init.d/是其软连接 mysql设为linux服务 cp /usr/local/mysql5/share/mysql/mysql.server /etc/init.d/mysqldchkconfig --add mysqldchkconfig --level 2345 mysqld onchown mysql:mysql -R /usr/local/mysql5/service mysqld start apa

centos 7 /etc/rc.local 开机不执行的问题

最近发现centos7 的/etc/rc.local不会开机执行,于是认真看了下/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 thi

CentOS 6.5 rc.local 开机不执行的原因之一

好久不动Linux,最近帮朋友弄了一下. 新买的阿里云主机,由于内存1GB所以选择了32bit的CentOS6.5. 安装软件和配置及其一些优化都很顺利,可是希望能在开机启动的时候启动web服务器和数据库,我的习惯做法是把启动脚本放在rc.local里面.重启发现根本没生效,测试了一下写法上没有任何问题.但是又找不到问题在哪里,Google了一下没找到什么有用的信息,偶然发现有人在写权限的问题,他写的是即使给了rc.local执行权限仍然无法执行,我看看下是他的脚本写错了.反过来我看了下我的rc