簡體   English   中英

無法將進程作為服務啟動? (代碼=退出,狀態=203/EXEC)

[英]Fail to start a process as a service? (code=exited, status=203/EXEC)

我需要將 cassandra 進程作為服務啟動。 為此,根據文檔將以下腳本放置在 /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 的 output

[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]#

首先,您可能患有急性copypasteitis

  • 初始化腳本是從一個位置(“互聯網”)獲得的
  • cassandra 文件位於不同於初始化腳本假定的路徑中

您的錯誤聲稱:

Nov 10 22:23:07 casstestnode1 systemd[1]: cassandra.service: control process exited, code=exited status=203

這個203通常意味着在exec*()系統調用時找不到某些可執行文件(即 exec 是用不存在的可執行文件路徑調用的)

其次,您使用的是基於systemd的發行版,因此無需使用 system V(舊的、過時的)類型的 init 腳本

讓我們看看如何讓您既熟悉又更新:

  1. 找到別人的 cassandra 的所謂工作系統單元文件(例如這個
  2. 在一邊打開 systemd 文檔: redhat official systemd doc
  3. 將單元文件放到正確的位置,編輯它
  4. 編輯完成后,運行systemctl daemon-reload
  5. 現在嘗試 systemd-way 啟動 cassandra: systemctl start cassandra

所以,在你找到它為什么會出現錯誤之后,請現在使用你,因為日志中的錯誤

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 手冊頁

所以根本原因是

  1. 確切路徑與/etc/rc.d/init.d/cassandra不同 - 您可以使用find /etc -name cassandra

  2. 文件不可執行的可能性較小,因為您可以手動執行。

我從這個鏈接中找到了答案。 原因是在#!/bin/bash之前我的 cassandra 腳本的開頭有一個空行。 一旦我刪除然后我執行以下兩個命令並修復了問題。

chkconfig --add cassandra

systemctl daemon-reload

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM