首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将systemv启动脚本转换为systemd服务?

如何将systemv启动脚本转换为systemd服务?
EN

Stack Overflow用户
提问于 2022-02-09 09:14:23
回答 1查看 746关注 0票数 0

关于将SysVinit文件转换为Systemd服务的建议将很有帮助。

目前,我正在使用systemv脚本,它将在基于STM32MP1的Avenger96板上每次启动后执行。现在,我必须从SysVinit切换到Systemd。但我不知道如何将init文件转换为相关的systemd文件。我使用Yocto和Ubuntu20.04作为构建系统。如果有人帮我开始的话,那就太好了。下面是init脚本和图像配方,它建立到init脚本的符号链接。

custom-script.sh,它安装在rootfs的etc/init.d/目录中。

代码语言:javascript
复制
#!/bin/sh

DAEMON="swupdate"
PIDFILE="/var/run/$DAEMON.pid"

PART_STATUS=$(sgdisk -A 4:get:2 /dev/mmcblk0)
if test "${PART_STATUS}" = "4:2:1" ; then
    ROOTFS=rootfs-2
else
    ROOTFS=rootfs-1
fi

if test -f /update-ok ; then
    SURICATTA_ARGS="-c 2"
    rm -f /update-ok
fi

start() {
    printf 'Starting %s: ' "$DAEMON"
    # shellcheck disable=SC2086 # we need the word splitting
    start-stop-daemon -b -q -m -S -p "$PIDFILE" -x "/usr/bin/$DAEMON" \
        -- -f /etc/swupdate/swupdate.cfg -L -e rootfs,${ROOTFS} -u "${SURICATTA_ARGS}"
    status=$?
    if [ "$status" -eq 0 ]; then
        echo "OK"
    else
        echo "FAIL"
    fi
    return "$status"
}

stop() {
    printf 'Stopping %s: ' "$DAEMON"
    start-stop-daemon -K -q -p "$PIDFILE"
    status=$?
    if [ "$status" -eq 0 ]; then
        rm -f "$PIDFILE"
        echo "OK"
    else
        echo "FAIL"
    fi
    return "$status"
}

restart() {
    stop
    sleep 1
    start
}

case "$1" in
        start|stop|restart)
        "$1";;
    reload)
        # Restart, since there is no true "reload" feature.
        restart;;
        *)
                echo "Usage: $0 {start|stop|restart|reload}"
                exit 1
esac

图像配方,它创建init.d dir并安装上面的脚本,并建立到rc4.d dir的符号链接。

代码语言:javascript
复制
custom-image.bb
代码语言:javascript
复制
.
.
inherit update-rc.d

SRC_URI = "file://custom-script.sh \
          "

S = "${WORKDIR}"

INITSCRIPT_PACKAGES = "${PN}"
INITSCRIPT_NAME = "custom-script.sh"
INITSCRIPT_PARAMS = "start 99 2 3 4 5 . "

do_install_append() {
    install -d ${D}${sysconfdir}/rc4.d
    install -d 644 ${D}${sysconfdir}/init.d
    install -m 0755 ${WORKDIR}/custom-script.sh ${D}${sysconfdir}/init.d
    ln -sf ../init.d/custom-script.sh ${D}${sysconfdir}/rc4.d/S99custom-script.sh
    ln -sf ../init.d/custom-script.sh ${D}${sysconfdir}/rc4.d/K99custom-script.sh
}

FILES_${PN} += "${sysconfdir}/init.d"

现在,我正尝试使用custom-script.sh来实现systemd的相同功能。在这种情况下可以使用systemd-sysv-generator吗?

而且,一旦我们切换到"systemd“,dir init.d会被完全删除吗?etc/init.d中存在的其他文件会发生什么?

有人能帮我开始吗?

你的帮助将不胜感激。

提前谢谢。

记者:如果这里缺少任何信息,请告诉我。

EN

回答 1

Stack Overflow用户

发布于 2022-02-12 21:50:08

使用systemd不会删除/etc/init.d

您是否检查了Ubuntu机器上的/etc/systemd/usr/lib/systemd以获得systemd脚本的示例。在systemd的手册页中,应该有足够的示例将sysv init脚本转换为systemd。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71046781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档