前段时间做了一个网站btdog磁力btdog电视直播。DHT爬虫需要消耗比较多的资源,原来的服务器不够用了,于是自己使用电脑搭了一台服务器,使用Fedora22系统。在Fedora22中自动写了些开机自启动脚本,但始终找不到放在哪里。折腾了下,发现原来Fedora 从15开始,系统初始化软件开始由initscript转向了systemd方式,原来要写开机启动脚本一般写在rc.local里面,但现在rc.local已经不存在了,不过systemd仍然有rc-local服务。

  编辑/usr/lib/systemd/system/rc-local.service  

#  This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version. # This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.d/rc.local is executable.
[Unit]
Description=/etc/rc.d/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target [Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=
RemainAfterExit=yes

  可见我们只要新建文件/etc/rc.d/rc.local 然后加入自己的脚本就可以了

  新建rc.local  

touch /etc/rc.d/rc.local

  vim /etc/rc.d/rc.local

#!/bin/bash
#下面是你需要执行的脚本 #####################################

  赋以可执行权限

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

  然后使用systemd开机自启动

systemctl enable rc-local.service

  提示错误如下: 

The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).

  这个时候,我们需要在/usr/lib/systemd/system/rc-local.service 中加入[Install]区域,用于告诉systemd需要在多用户启动时还是图形启动时自启动这个脚本

  编辑/usr/lib/systemd/system/rc-local.service

#  This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version. # This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.d/rc.local is executable.
[Unit]
Description=/etc/rc.d/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target [Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=
RemainAfterExit=yes
SysVStartPriority= [Install]
WantedBy=multi-user.target

  好了,然后在使用systemd开机自启动

systemctl enable rc-local.service 

  然后查看启动状态

#systemctl status rc-local.service
● rc-local.service - /etc/rc.d/rc.local Compatibility
Loaded: loaded (/usr/lib/systemd/system/rc-local.service; enabled; vendor preset: disabled)
Active: active (exited) since 一 -- :: CST; 28min ago 6月 :: btdog systemd[]: Starting /etc/rc.d/rc.local Compatibility...
6月 :: btdog rc.local[]: /etc/rc.d/rc.local:行4: [Install]: 未找到命令
6月 :: btdog systemd[]: Started /etc/rc.d/rc.local Compatibility.
6月 :: btdog systemd[]: Started /etc/rc.d/rc.local Compatibility.
6月 :: btdog systemd[]: [/usr/lib/systemd/system/rc-local.service:] Support for option SysVStartPriority=...ignored
Hint: Some lines were ellipsized, use -l to show in full.

  启动成功~~

Fedora 22(15以上版本)开机自启动脚本的更多相关文章

  1. 转载:ubuntu 下添加简单的开机自启动脚本

    转自:https://www.cnblogs.com/downey-blog/p/10473939.html linux下添加简单的开机自启动脚本 在linux的使用过程中,我们经常会碰到需要将某个自 ...

  2. linux添加开机自启动脚本示例详解

    linux下(以RedHat为范本)添加开机自启动脚本有两种方法,先来简单的; 一.在/etc/rc.local中添加如果不想将脚本粘来粘去,或创建链接什么的,则:step1. 先修改好脚本,使其所有 ...

  3. Linux定时任务与开机自启动脚本(cron与crontab)

    开机自启动脚本 网上常见的脚本开机自启方法是: 假设要自启的脚本位于 /home/user/test.sh 给脚本可执行的权限 sudo chmod +x /home/user/test.sh 将脚本 ...

  4. Linux开机自启动脚本的总结

    一.在/etc/rc.local中添加 如果不想将脚本粘来粘去,或创建链接什么的, 则: step1. 先修改好脚本,使其所有模块都能在任意目录启动时正常执行; step2. 再在/etc/rc.lo ...

  5. Centos开机自启动脚本的制作

    原文地址:http://www.2cto.com/os/201306/220559.html 我的一个Centos开机自启动脚本的制作   一.切换到/etc/init.d/   二.制作sh脚本 v ...

  6. linux 开机自启动脚本

    在/etc/rc.local文件中添加自启动命令(其中一种方法) 1.案例,就用博主本人之前发的博文 “nginx + flask + uwsgi + centos + python3 搭建web项目 ...

  7. linux实现开机自启动脚本

    Linux下(以RedHat为范本)添加开机自启动脚本有两种方法,先来简单的; 一.在/etc/rc.local中添加如果不想将脚本粘来粘去,或创建链接什么的,则:step1. 先修改好脚本,使其所有 ...

  8. 红帽linux系统开机自启动脚本。

    其实很多东西在最后完成以后会觉得也就那样,有意思的是探究的过程. 前段时间老板要求把一个程序做成linux系统开机自启动脚本的模式. 首先你需要写一个脚本. 我这边建立了一个.sh的脚本,就是用脚本启 ...

  9. apache 开机自启动脚本设置

    默认我们源码编译安装apache,是不能使用service这个命令来启动的,通常我们启动的命令是: [root@localhost httpd-2.2.16]# /usr/local/apache2/ ...

随机推荐

  1. phpStorm 各种快捷键

    1. ctrl + shift + n: 打开工程中的文件(类似于eclipse中的ctrl+shift+R),目的是打开当前工程下任意目录的文件. 2. ctrl + j: 输出模板 3. ctrl ...

  2. Ubuntu 无线连接能上网,但是有线连接不能上

    这两天装Ubuntu,遇到小问题.最头疼的还是上网,过去我装了Ubuntu时,都是插上网线就能直接上网,这次就不行了. 我刚点开一个网页,接下来点就不能上了,但是无线连接就可以正常上网. 我在一个论坛 ...

  3. Oracle insert update 时间处理

    24小时表示方法:to_date(’ ::’,’yyyy-mm-dd hh24:mi:ss’) 12小时表示方法:to_date(’ ::’,’yyyy-mm-dd hh:mi:ss’) ','S75 ...

  4. CGI、FastCGI和php-fpm的区别

    参考网上的描述,将网上的描述内容,整理进来: 首先,CGI是干嘛的?CGI是为了保证web server传递过来的数据是标准格式的,方便CGI程序的编写者.web server(比如说nginx)只是 ...

  5. [ES6] Generators

    Example 1: function *topicList(){ yield "ES2015"; yield "Semi-colons: good or bad?&qu ...

  6. 可失败构造器(Failable Initializers)

    Xcode6.1中Swift的最新版本是1.1,在该版本中引入了一个新的特性:可失败构造器.通过构造器初始化实际上是给class或struct的每一个存储属性(参数)提供初始值,进行对象实例化的过程. ...

  7. Android的TextView使用Html来处理图片显示、字体样式、超链接等

    一.[Android实例]实现TextView里的文字有不同颜色 转eoe:http://www.eoeandroid.com/thread-4496-1-1.html import android. ...

  8. 阿里云 RDS 怎么保证高可用性

    RDS在系统构建之初,从网络到硬件再到系统都是基于高可用设计,他可以做到故障30秒无缝转移,对应用完全透明. 当一个数据库实例发生故障时, 另一个会立即顶上,而且对应用是完全透明的.你无需变更应用的连 ...

  9. Linq 关键字

    from var lowNums = from num in numbers            where num < 5            select num; numbers 是数 ...

  10. android*API19

     android android.accessibilityservice android.accounts android.animation android.app android.app.adm ...