[英]Why does my Erlang boot script work from console but does not work when run from init system (sysvinit, upstart, systemd)?
[英]How to convert sysvinit script to systemd on Manjaro
首先,請不要將此帖子視為系統評論或批評者,而應僅是簡單地尋求幫助。
由於我無法通過systemd文檔找到解決此問題的方法,因此這個問題已經解決了將近一年半,但從未收到過任何答案。
因此,這是上下文:
我有一個程序(/ opt / myprog),可以在啟動時作為守護程序出售。
當使用以前的Debian,LMDE,Mint或Ubuntu操作系統時,我將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,因此,我嘗試使用以下腳本將sysVinit腳本改編為systemd可以,但是太有限了(myprog.service):
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
預先感謝您的時間和幫助。
systemd
不支持systemctl
自定義參數實現。
因此, systemctl status myprog
將根據執行Exec*
設置顯示結果。
systemctl show myprog
使用Description
因此如果需要,您可以在Description
中使用版本。
如果您不想以守護程序的身份運行程序,則可以在systemd
之外啟動它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.