我为我的守护进程创建了一个RPM包,在安装时创建了/etc/init.d/下的服务初始化脚本 现在我想为CentOS7.1移植这个RPM包,并使用systemd框架通过启动和管理员通过启动/停止命令进行服务启动。
我找不到任何教程。请帮忙。
编辑: 我尝试了msuchy给出的建议。
我试过,这是我的观察
基于sysV的框架(CentOS6.5)
[root@adil work]# /etc/init.d/daemon_script status
Service daemon: Stopped
[root@adil work]# /etc/init.d/daemon_script start
Starting daemon: Initializing daemon... [ OK ]
[root@adil work]#
[root@adil work]# /etc/init.d/daemon_script status
Service daemon: Running
[root@adil work]#
[root@adil work]# /etc/init.d/daemon_script stop
Shutting down parent daemon: [ OK ]
[root@adil work]# /etc/init.d/daemon_script status
Service daemon: Stopped
[root@adil work]#
===========
在基于systemd的框架上,我在CentOS7.1上安装了相同的RPM
[root@localhost x86_64]# /etc/init.d/daemon_script
Usage: /etc/init.d/daemon_script {start|stop|restart|status}
[root@localhost x86_64]# /etc/init.d/daemon_script start
Starting daemon_script (via systemctl): Warning: Unit file of daemon_script.service changed on disk, 'systemctl daemon-reload' recommended.
Job for daemon_script.service failed. See 'systemctl status daemon_script.service' and 'journalctl -xn' for details.
[FAILED]
[root@localhost x86_64]# systemctl daemon-reload
[root@localhost x86_64]# systemctl status daemon_script.service
daemon_script.service - SYSV: start and stop Test daemon service.
Loaded: loaded (/etc/rc.d/init.d/daemon_script)
Active: failed (Result: exit-code) since Fri 2015-09-11 15:30:44 IST; 32s ago
Sep 11 15:30:44 localhost.localdomain systemd[1]: Starting SYSV: start and st...
Sep 11 15:30:44 localhost.localdomain systemd[1]: daemon_script.service: cont...
Sep 11 15:30:44 localhost.localdomain systemd[1]: Failed to start SYSV: start...
Sep 11 15:30:44 localhost.localdomain systemd[1]: Unit daemon_script.service ...
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost x86_64]# systemctl status daemon_script.service -l
daemon_script.service - SYSV: start and stop Test daemon service.
Loaded: loaded (/etc/rc.d/init.d/daemon_script)
Active: failed (Result: exit-code) since Fri 2015-09-11 15:30:44 IST; 46s ago
Sep 11 15:30:44 localhost.localdomain systemd[1]: Starting SYSV: start and stop Test daemon service....
Sep 11 15:30:44 localhost.localdomain systemd[1]: daemon_script.service: control process exited, code=exited status=203
Sep 11 15:30:44 localhost.localdomain systemd[1]: Failed to start SYSV: start and stop Test daemon service..
Sep 11 15:30:44 localhost.localdomain systemd[1]: Unit daemon_script.service entered failed state.
[root@localhost x86_64]#
journalctl -xn
的输出 -- Logs begin at Fri 2015-09-11 14:50:35 IST, end at Fri 2015-09-11 15:40:01 IST. --
Sep 11 15:31:03 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/dm-event.socket:10] Unknown lvalue 'RemoveOnStop' in section 'Socket'
Sep 11 15:39:33 localhost.localdomain systemd[1]: Starting SYSV: start and stop Test daemon service....
-- Subject: Unit daemon_script.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit daemon_script.service has begun starting up.
Sep 11 15:39:33 localhost.localdomain systemd[8509]: Failed at step EXEC
spawning /etc/rc.d/init.d/daemon_script: Exec format error
-- Subject: Process /etc/rc.d/init.d/daemon_script could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /etc/rc.d/init.d/daemon_script could not be executed and failed.
--
-- The error number returned while executing this process is 8.
Sep 11 15:39:33 localhost.localdomain systemd[1]: daemon_script.service: control process exited, code=exited status=203
Sep 11 15:39:33 localhost.localdomain systemd[1]: Failed to start SYSV: start and stop Test daemon service..
-- Subject: Unit daemon_script.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit daemon_script.service has failed.
--
-- The result is failed.
Sep 11 15:39:33 localhost.localdomain systemd[1]: Unit daemon_script.service entered failed state.
Sep 11 15:40:01 localhost.localdomain systemd[1]: Created slice user-0.slice.
-- Subject: Unit user-0.slice has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit user-0.slice has finished starting up.
--
-- The start-up result is done.
Sep 11 15:40:01 localhost.localdomain systemd[1]: Starting Session 7 of user root.
-- Subject: Unit session-7.scope has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-7.scope has begun starting up.
Sep 11 15:40:01 localhost.localdomain systemd[1]: Started Session 7 of user root.
-- Subject: Unit session-7.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-7.scope has finished starting up.
--
-- The start-up result is done.
Sep 11 15:40:01 localhost.localdomain CROND[8528]: (root) CMD (/usr/lib64/sa/sa1 1 1)
[root@localhost x86_64]#
答案 0 :(得分:2)
您无需迁移脚本。
可能更好,你可以利用Systemd的一些有趣功能,你的文件会更小。但是你不需要迁移。 Systemd也可以正常使用SysV init文件。
您无法在CentOS 7安装上找到任何SysV init文件,因为Red Hat打包程序(创建CentOS的用户)会努力打包并将所有SysV文件迁移到单元文件。但你不需要。
这只是您需要完成的一项任务。放置新的SysV文件后,必须使用
重新加载systemd manager配置# systemctl daemon-reload
就是这样。 我举个小例子
# cat /etc/init.d/foo
#!/usr/bin/sh
echo ahoy
# chmod a+x /etc/init.d/foo
# systemctl start foo
Failed to start foo.service: Unit foo.service failed to load: No such file or directory.
# systemctl daemon-reload
# systemctl start foo
# journalctl -xn
-- Subject: Unit foo.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit foo.service has finished starting up.
--
-- The start-up result is done.
# service foo start
ahoy
所以你可以像使用CentOS 6一样使用所有命令(chkconfig,service)。当你有时间的时候,你可以学习man systemd.unit
(5)和其他一些手册页(参见&# 34;另见该手册页的第34页。