码迷,mamicode.com
首页 > 其他好文 > 详细

Fedora 22(15以上版本)开机自启动脚本

时间:2015-06-22 22:19:20      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

  前段时间做了一个网站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=0
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=0
RemainAfterExit=yes
SysVStartPriority=99

[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 一 2015-06-22 20:23:23 CST; 28min ago

6月 22 20:23:23 btdog systemd[1]: Starting /etc/rc.d/rc.local Compatibility...
6月 22 20:23:23 btdog rc.local[3973]: /etc/rc.d/rc.local:行4: [Install]: 未找到命令
6月 22 20:23:23 btdog systemd[1]: Started /etc/rc.d/rc.local Compatibility.
6月 22 20:27:28 btdog systemd[1]: Started /etc/rc.d/rc.local Compatibility.
6月 22 20:37:05 btdog systemd[1]: [/usr/lib/systemd/system/rc-local.service:20] Support for option SysVStartPriority=...ignored
Hint: Some lines were ellipsized, use -l to show in full.

  启动成功~~

Fedora 22(15以上版本)开机自启动脚本

标签:

原文地址:http://www.cnblogs.com/kekukele/p/4593873.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!