首先,请不要将这篇文章视为系统评论或批评,而只是简单地将其视为请求帮助。
由于我无法通过systemd文档找到这个问题的解决方案,所以我几乎一年半以来都没有解决这个问题,也从未得到任何答案。
因此,这里是上下文:
我有一个程序(/opt/myprog),它可以在引导时作为守护程序服务。
当使用以前的Debian、LMDE、Mint或Ubuntu OSes时,我使用SysVinit和以下脚本( /etc/init.d文件夹中的myprog.sh):
MYPROG_PATH=/opt/myprog_64
NAME="myprog"
START="-d"
STOP="-k"
TEST=""
VERSION="-v"
SCRIPTNAME=/etc/init.d/$NAME
STARTMESG="\nStarting $NAME in deamon mode.\n"
UPMESG="\$NAME is running.\n"
DOWNMESG="\$NAME is not running!\n"
TESTMESG="\nStarting NAME in client mode.\nHit Ctrl+C (or close the terminal) to stop mprog.\n"
STATUS=`pidof $NAME`
# Exit if myprog is not installed
[ -x "$MYPROG_PATH/$NAME" ] || exit 0
case "$1" in
start)
sleep 3
echo $STARTMESG
cd $MYPROG_PATH
./$NAME $START
;;
stop)
cd $MYPROG_PATH
./$NAME $STOP
;;
status)
if [ "$STATUS" > 0 ] ; then
echo $UPMESG
else
echo $DOWNMESG
fi
;;
restart)
cd $MYPROG_PATH
./$NAME $STOP
echo $STARTMESG
./$NAME $START
;;
version)
cd $MYPROG_PATH
./$NAME $VERSION
;;
test)
cd $MYPROG_PATH
echo $TESTMESG
./$NAME
;;
*)
echo "Usage: $SCRIPTNAME {start|status|restart|stop|version|test}" >&2
exit 3
;;
esac
:现在,由于systemd显然将被广泛采用来取代SysVinit,包括未来的Debian、Mint和Ubuntu发行版,就像它与CentOS、Fedroa或Ach和Manjaro一样,我尝试使用以下脚本(myprog.service)将我的sysVinit脚本调整为systemd:
Description=myprog
ConditionFileExecutable=/opt/myprog_64
After=NetworkManager.service
[Service]
Type=oneshot
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ExecStart=/opt/myprog -d
ExecStop=/opt/myprog -k
ExecRestart=/opt/myprog-k : /opt/myprog -d
TimeoutSec=0
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target然而,由于systemd被宣传为兼容且比SysVinit更灵活,谁能告诉我如何添加我在myprog.sh sysVinit脚本中定义的以下三个等效开关(状态、测试和版本),而不用经典而粗俗的回答:“人是你的朋友”?
/opt/myprog status to display the myprog status (i.e. running or not)
/opt/myprog test to start myprog not as a deamon
/opt/myprog version to display the release of myprog提前感谢您的时间和帮助。
发布于 2018-10-15 08:20:43
systemd不支持systemctl参数的自定义实现。
因此,systemctl status myprog将根据Exec*设置的执行情况显示结果。
systemctl show myprog使用Description,因此如果需要,您可以在描述中使用版本。
如果您不想将程序作为守护进程运行,那么可以在systemd外部启动它。
https://stackoverflow.com/questions/52750011
复制相似问题