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