[ 已解决 ] 关于 openSUSE 的 chkconfig 问题?

我想问问,为什么我使用 chkconfig apache2 on 后,用 chkconfig --list 发现 apache 的状态没有改变,运行一下 service apache2 status 发现服务器其实已经启动了,但是为什么 chkconfig --list 后的状态没有改变,如何解决?

很简单。因为 openSUSE 从 12.1 开始迁移到 systemd,12.3 迁移完成结束 systemd 和 sysvinit 启动脚本并存的局面,全部主要软件包均已实现 systemd 启动。

blog.crozat.net/2011/06/road-to-systemd-for-opensuse-121.html

这是 openSUSE 的 systemd 专家的博客。

换句话说,我们不用红帽/Ubuntu 的 chkconfig。再换句话说,我们一直都没有用过 chkconfig,即使是 sysvinit 年代我们用的也是更加高级的 SuSEconfig。不要用 Ubuntu way 去学习 openSUSE,一直都是它学我们,是它不够高级不是我们落后,所以方向不要搞错。

darkpink:/usr/bin # chkconfig apache2 on
ln -s '/lib/systemd/system/apache2.service' '/etc/systemd/system/multi-user.target.wants/apache2.service




darkpink:/usr/bin # service apache2 status
apache2.service - apache
          Loaded: loaded (/lib/systemd/system/apache2.service; enabled)
          Active: inactive (dead)
          CGroup: name=systemd:/system/apache2.service

首先注意那个 ln -s 里面的内容了吗?chkconfig apache2 on 相当于 systemctl enable apache2.service

其次注意这可不是 active (running)。enable 在 systemd 中是一种非常普遍的状态,简单说只要你装了软件包,没有手动去 mask/disable 掉服务,那么它就是 enable 的。

最后,如果你看得仔细点的话,chkconfig 本身就已经告诉你了:

chkconfig -l

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

...

apache2 使用原生 systemd 服务,现在 openSUSE 只有小猫小狗还使用 sysvinit 了。而即使是这种小猫小狗,systemd 也提供了兼容启动方式,它没有 systemd 脚本你一样可以用下面的方法启动。

systemd 下启动服务的方法是

systemctl start apache2.service

更多学习资源:http://doc.opensuse.org/documentation/html/openSUSE/opensuse-reference/cha.systemd.html (中文版翻译中)

1赞

考虑到兼容性,opensuse中的chkconfig其实是一个perl脚本,其内部最终还是调用systemd来实现管理不同level下的自启。所以直接用chkconfig也是可以工作的,至于你再次chkconfig --list还是没有,那是你没执行成功,注意看输出结果,是没有权限还是依赖服务没有启动等。

~ » file /sbin/chkconfig
/sbin/chkconfig: Perl script, ASCII text executable

一个错误的示例:依赖服务portmap。

~ » sudo chkconfig ypbind on
insserv: Note: sysvinit service ypbind is shadowed by systemd ypbind.service,
Forwarding request to '/bin/systemctl --no-reload --root / enable ypbind.service'.
insserv: Forward service request to systemctl returned error status : 256
insserv: FATAL: service portmap has to be enabled to use service ypbind
insserv: exiting now!
/sbin/insserv failed, exit code 1

另一个错误示例:权限不够

~ » chkconfig sshd on
insserv: Note: sysvinit service sshd is shadowed by systemd sshd.service,
Forwarding request to '/bin/systemctl --no-reload --root / enable sshd.service'.
Operation failed: Permission denied
insserv: Forward service request to systemctl returned error status : 256
insserv: can not symlink(../sshd, rc3.d/S08sshd): Permission denied
insserv: can not symlink(../sshd, rc3.d/K01sshd): Permission denied
insserv: can not symlink(../sshd, rc5.d/S08sshd): Permission denied
insserv: can not symlink(../sshd, rc5.d/K01sshd): Permission denied
insserv: fopen(.depend.stop): Permission denied

PS:该命令仅仅是将/lib/systemd/system/下的service文件软链接到该目录下不同level的子目录里而已,并没有启动服务的操作,所以你这里用service看到启动了(比如安装后没重启,或手动启动的)与chkconfig执行结果并不一定有因果关系(不重启的情况)。