使用upstart / systemd检测创建sysv init脚本

时间:2015-01-19 21:50:41

标签: linux init upstart systemd

我正在尝试为Ubuntu upstart / Debian SysV和systemd系统创建一组通用的init脚本。

我意识到新贵,我总是可以在我的/etc/init.d/appname文件中进行简单的检查:

. /lib/lsb/init-functions
check_for_upstart() {
    if init_is_upstart; then
        echo "Upstarted detected. Use upstart service commands. Exiting." >&2
        exit 1
    fi
}

(或者我可以更好地将相关命令转发给upstart,就像一些Ubuntu脚本那样)

是否有类似的方法来检测systemd是否正在使用并退出或重定向到systemctl?我意识到很多openSUSE脚本重定向到systemctl,但是看一下脚本,我不明白他们是如何做到这一点的。我通过它们包含的/etc/rc_status文件猜测它,但这似乎是特定于openSUSE的,并不适用于CentOS。

最终我想支持Ubuntu 14,Debian 7,CentOS / RHEL 7和openSUSE(任何systemd)。因此,我的systemv init脚本实际上只适用于Debian,并且只会在每个其他发行版上存在消息(或以某种标准方式重定向到systemctl / upstart)。

是否有任何示例/最佳做法可以实现这一目标?

0 个答案:

没有答案
相关问题