1
0

fix: 优化omcd脚本,增加服务存在性检查

This commit is contained in:
TsMask
2025-04-21 16:27:49 +08:00
parent 38f6652301
commit 9ee596f01d

View File

@@ -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
;;
*)