gpt4 book ai didi

linux - 无法将进程作为服务启动? (代码=已退出,状态=203/EXEC)

转载 作者:太空宇宙 更新时间:2023-11-04 04:38:15 33 4
gpt4 key购买 nike

我需要将 cassandra 进程作为服务启动。为此,按照 doc 将以下脚本放置在/etc/init.d 目录中

这是我放置在 init 目录中的脚本。

#!/bin/bash
# chkconfig: 2345 99 01
# description: Cassandra

. /etc/rc.d/init.d/functions

CASSANDRA_HOME=/home/cassandra/binaries/cassandra
CASSANDRA_BIN=$CASSANDRA_HOME/bin/cassandra
CASSANDRA_NODETOOL=$CASSANDRA_HOME/bin/nodetool
CASSANDRA_LOG=$CASSANDRA_HOME/logs/cassandra.log
CASSANDRA_PID=$CASSANDRA_HOME/cassandra.pid
CASSANDRA_LOCK=$CASSANDRA_HOME/cassandra.lock
PROGRAM="cassandra"

if [ ! -f $CASSANDRA_BIN ]; then
echo "File not found: $CASSANDRA_BIN"
exit 1
fi

RETVAL=0

start() {
if [ -f $CASSANDRA_PID ] && checkpid `cat $CASSANDRA_PID`; then
echo "Cassandra is already running."
exit 0
fi
echo -n $"Starting $PROGRAM: "
$CASSANDRA_BIN -p $CASSANDRA_PID -R >> $CASSANDRA_LOG 2>&1
sleep 60
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
touch $CASSANDRA_LOCK
echo_success
else
echo_failure
fi
echo
return $RETVAL
}

stop() {
if [ ! -f $CASSANDRA_PID ]; then
echo "Cassandra is already stopped."
exit 0
fi
echo -n $"Stopping $PROGRAM: "
# $CASSANDRA_NODETOOL -h 127.0.0.1 decommission
if kill `cat $CASSANDRA_PID`; then
RETVAL=0
rm -f $CASSANDRA_LOCK
echo_success
else
RETVAL=1
echo_failure
fi
echo
[ $RETVAL = 0 ]
}

status_fn() {
if [ -f $CASSANDRA_PID ] && checkpid `cat $CASSANDRA_PID`; then
echo "Cassandra is running."
exit 0
else
echo "Cassandra is stopped."
exit 1
fi
}

case "$1" in
start)
start
;;
stop)
stop
;;
status)
status_fn
;;
restart)
stop
start
;;
*)
echo $"Usage: $PROGRAM {start|stop|restart|status}"
RETVAL=3
esac

exit $RETVAL

但是,当执行 service cassandra start 时,它最终出现错误,如下所示。

[root@casstestnode1 init.d]# service cassandra start
Starting cassandra (via systemctl): Job for cassandra.service failed because the control process exited with error code. See "systemctl status cassandra.service" and "journalctl -xe" for details.
[FAILED]
[root@casstestnode1 init.d]#

[root@casstestnode1 init.d]# systemctl status cassandra.service
● cassandra.service - SYSV: Cassandra
Loaded: loaded (/etc/rc.d/init.d/cassandra)
Active: failed (Result: exit-code) since Sun 2019-11-10 22:23:07 IST; 41s ago
Docs: man:systemd-sysv-generator(8)
Process: 2624 ExecStart=/etc/rc.d/init.d/cassandra start (code=exited, status=203/EXEC)

Nov 10 22:23:07 casstestnode1 systemd[1]: Starting SYSV: Cassandra...
Nov 10 22:23:07 casstestnode1 systemd[1]: cassandra.service: control process exited, code=exited status=203
Nov 10 22:23:07 casstestnode1 systemd[1]: Failed to start SYSV: Cassandra.
Nov 10 22:23:07 casstestnode1 systemd[1]: Unit cassandra.service entered failed state.
Nov 10 22:23:07 casstestnode1 systemd[1]: cassandra.service failed.
[root@casstestnode1 init.d]#

我重新启动虚拟机并再次重试,错误仍然相同。请各位linux高手帮忙。

此外,这里是journalctl -xe 的输出

[root@casstestnode1 init.d]# journalctl -xe
-- Unit session-3153.scope has begun starting up.
Nov 11 23:55:01 casstestnode1 systemd[1]: Started Session 3154 of user cassandra.
-- Subject: Unit session-3154.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-3154.scope has finished starting up.
--
-- The start-up result is done.
Nov 11 23:55:01 casstestnode1 systemd[1]: Starting Session 3154 of user cassandra.
-- Subject: Unit session-3154.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-3154.scope has begun starting up.
Nov 11 23:55:01 casstestnode1 CROND[24584]: (cassandra) CMD (. /home/cassandra/test/cr.sh)
Nov 11 23:55:01 casstestnode1 CROND[24585]: (cassandra) CMD (date >> /home/cassandra/test/ll.txt)
Nov 11 23:55:01 casstestnode1 postfix/pickup[23967]: A5210F1C27: uid=995 from=<cassandra>
Nov 11 23:55:01 casstestnode1 postfix/cleanup[24090]: A5210F1C27: message-id=<20191111182501.A5210F1C27@casstestnode1.localdomain>
Nov 11 23:55:01 casstestnode1 postfix/qmgr[2035]: A5210F1C27: from=<cassandra@casstestnode1.localdomain>, size=837, nrcpt=1 (queue activ
Nov 11 23:55:01 casstestnode1 postfix/pickup[23967]: A8301F1C29: uid=995 from=<cassandra>
Nov 11 23:55:01 casstestnode1 postfix/cleanup[24315]: A8301F1C29: message-id=<20191111182501.A8301F1C29@casstestnode1.localdomain>
Nov 11 23:55:01 casstestnode1 postfix/qmgr[2035]: A8301F1C29: from=<cassandra@casstestnode1.localdomain>, size=845, nrcpt=1 (queue activ
Nov 11 23:55:01 casstestnode1 postfix/local[24021]: A5210F1C27: to=<cassandra@casstestnode1.localdomain>, orig_to=<cassandra>, relay=loc
Nov 11 23:55:01 casstestnode1 postfix/cleanup[24090]: A987AF1C2A: message-id=<20191111182501.A987AF1C2A@casstestnode1.localdomain>
Nov 11 23:55:01 casstestnode1 postfix/qmgr[2035]: A987AF1C2A: from=<>, size=2878, nrcpt=1 (queue active)
Nov 11 23:55:01 casstestnode1 postfix/bounce[24164]: A5210F1C27: sender non-delivery notification: A987AF1C2A
Nov 11 23:55:01 casstestnode1 postfix/qmgr[2035]: A5210F1C27: removed
Nov 11 23:55:01 casstestnode1 postfix/local[23698]: A8301F1C29: to=<cassandra@casstestnode1.localdomain>, orig_to=<cassandra>, relay=loc
Nov 11 23:55:01 casstestnode1 postfix/cleanup[24315]: AA5AFF1C27: message-id=<20191111182501.AA5AFF1C27@casstestnode1.localdomain>
Nov 11 23:55:01 casstestnode1 postfix/qmgr[2035]: AA5AFF1C27: from=<>, size=2886, nrcpt=1 (queue active)
Nov 11 23:55:01 casstestnode1 postfix/bounce[24164]: A8301F1C29: sender non-delivery notification: AA5AFF1C27
Nov 11 23:55:01 casstestnode1 postfix/qmgr[2035]: A8301F1C29: removed
Nov 11 23:55:01 casstestnode1 postfix/local[24021]: A987AF1C2A: to=<cassandra@casstestnode1.localdomain>, relay=local, delay=0.01, delay
Nov 11 23:55:01 casstestnode1 postfix/qmgr[2035]: A987AF1C2A: removed
Nov 11 23:55:01 casstestnode1 postfix/local[23698]: AA5AFF1C27: to=<cassandra@casstestnode1.localdomain>, relay=local, delay=0.01, delay
Nov 11 23:55:01 casstestnode1 postfix/qmgr[2035]: AA5AFF1C27: removed
lines 1923-1959/1959 (END)
[root@casstestnode1 init.d]#
[root@casstestnode1 init.d]#

当我手动运行脚本时

[root@casstestnode1 init.d]#
[root@casstestnode1 init.d]# ./cassandra start
Starting cassandra: [ OK ]
[root@casstestnode1 init.d]# ./cassandra status
Cassandra is running.
[root@casstestnode1 init.d]#
[root@casstestnode1 init.d]#
[root@casstestnode1 init.d]# service cassandra status
Cassandra is running.
[root@casstestnode1 init.d]# ./cassandra stop
Stopping cassandra: [ OK ]
[root@casstestnode1 init.d]#
[root@casstestnode1 init.d]# ./cassandra status
Cassandra is stopped.
[root@casstestnode1 init.d]# service cassandra status
Cassandra is stopped.
[root@casstestnode1 init.d]#

最佳答案

203 EXIT_EXEC   The actual process execution failed (specifically, the execve(2) system call). Most likely this is caused by a missing or non-accessible executable file

根据 systemd.exec man page

所以根本原因是

  1. 确切路径与/etc/rc.d/init.d/cassandra不同 - 您可以使用find/etc -name cassandra

  2. 文件不可执行的可能性较小,因为您可以手动执行此操作。

关于linux - 无法将进程作为服务启动? (代码=已退出,状态=203/EXEC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58790889/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com