我似乎是 Fedora15 的时候才开始转用 Fedora 的,之前使用的是 RedFlag DT6sp3 ,也是从 Fedora15 的时候,系统 init 软件就从 initscript 替换为了 systemd方式。刚开始觉得还不习惯,但也没有太在意。

最近想写点东西到 rc.local 里,实现开机自启动,但发现 rc.local 已经不存在了,几经查找,原来 systemd 里有 rc-local.service ,只需要再写一个 rc.local 的脚本即可。

1、编辑 /usr/lib/systemd/system/rc-local.service 文件:
[php]
[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
[/php]
其中 Install 那部分是自己写的,multi-user.target 代表3级别,graphical.target 代表5级别。
[php]
lrwxrwxrwx. 1 root root runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root runlevel6.target -> reboot.target
[/php]

2、编辑 /etc/rc.d/rc.local 文件:
[php]
# cat /etc/rc.d/rc.local
#!/bin/bash
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[/php]
其中 开头一定要写 #!/bin/bash ,然后 xxxxxx 代表自定义内容,例如要开机启动什么脚本或设置的,可以写在这里;

3、给 /etc/rc.d/rc.local 可执行权限:
[php]
#chmod +x /etc/rc.d/rc.local
[/php]

4、开启 rc-local.service 服务:
[php]
#systemctl enable rc-local.service
#systemctl –system daemon-reload
#systemctl start 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; disabled)
Active: active (exited) since Sat, 27 Apr 2013 11:36:04 +0800; 36min ago
Process: 26325 ExecStart=/etc/rc.d/rc.local start (code=exited, status=0/SUCCESS)
Main PID: 26115 (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/rc-local.service
[/php]

此时,已经搞定了,后期会整理一些 systemd 的资料,或许会久一点,最近公事、私事太多。