From 9ee596f01def0ed1063f77acc3b084c97476201b Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 21 Apr 2025 16:27:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96omcd=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E6=80=A7=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- linux/usr/local/bin/omcd | 52 ++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/linux/usr/local/bin/omcd b/linux/usr/local/bin/omcd index 90d9408..77bac3e 100644 --- a/linux/usr/local/bin/omcd +++ b/linux/usr/local/bin/omcd @@ -1,28 +1,53 @@ #!/bin/bash ServiceList="omc sshsvc" +BinDir="/usr/local/bin" + +# Check if the service exists +check_service() { + systemctl list-unit-files | grep -q "$1.service" + return $? +} case "$1" in start) - for v in $ServiceList;do + for v in $ServiceList; do + if ! check_service "$v"; then + echo "Service $v does not exist" + continue + fi systemctl start $v if [ $? = 0 ]; then - echo "starting $v process done" - fi + echo "Starting $v process done" + else + echo "Failed to start $v" + fi sleep 1 done ;; status) - for v in $ServiceList;do - systemctl status $v + for v in $ServiceList; do + if ! check_service "$v"; then + echo "Service $v does not exist" + continue + fi + echo "=== Status of $v ===" + systemctl status --no-pager -n 20 $v + echo "" done ;; stop) - for v in $ServiceList;do - systemctl stop $procName + for v in $ServiceList; do + if ! check_service "$v"; then + echo "Service $v does not exist" + continue + fi + systemctl stop $v if [ $? = 0 ]; then - echo "Stopping $v process done" - fi + echo "Stopping $v process done" + else + echo "Failed to stop $v" + fi done ;; restart) @@ -31,9 +56,12 @@ case "$1" in $0 start ;; version) - local BinDir=/usr/local/bin - for v in $ServiceList;do - $BinDir/$v --version + for v in $ServiceList; do + if [ -x "$BinDir/$v" ]; then + $BinDir/$v --version + else + echo "$v binary not found in $BinDir" + fi done ;; *)