关于将SysVinit文件转换为Systemd服务的建议将很有帮助。
目前,我正在使用systemv脚本,它将在基于STM32MP1的Avenger96板上每次启动后执行。现在,我必须从SysVinit切换到Systemd。但我不知道如何将init文件转换为相关的systemd文件。我使用Yocto和Ubuntu20.04作为构建系统。如果有人帮我开始的话,那就太好了。下面是init脚本和图像配方,它建立到init脚本的符号链接。
custom-script.sh,它安装在rootfs的etc/init.d/目录中。
#!/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的符号链接。
custom-image.bb.
.
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中存在的其他文件会发生什么?
有人能帮我开始吗?
你的帮助将不胜感激。
提前谢谢。
记者:如果这里缺少任何信息,请告诉我。
发布于 2022-02-12 21:50:08
使用systemd不会删除/etc/init.d
您是否检查了Ubuntu机器上的/etc/systemd和/usr/lib/systemd以获得systemd脚本的示例。在systemd的手册页中,应该有足够的示例将sysv init脚本转换为systemd。
https://stackoverflow.com/questions/71046781
复制相似问题