73 lines
1.7 KiB
Bash
73 lines
1.7 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
ServiceList="omc"
|
|
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
|
|
if ! check_service "$v"; then
|
|
echo "Service $v does not exist"
|
|
continue
|
|
fi
|
|
systemctl start $v
|
|
if [ $? = 0 ]; then
|
|
echo "Starting $v process done"
|
|
else
|
|
echo "Failed to start $v"
|
|
fi
|
|
sleep 1
|
|
done
|
|
;;
|
|
status)
|
|
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
|
|
if ! check_service "$v"; then
|
|
echo "Service $v does not exist"
|
|
continue
|
|
fi
|
|
systemctl stop $v
|
|
if [ $? = 0 ]; then
|
|
echo "Stopping $v process done"
|
|
else
|
|
echo "Failed to stop $v"
|
|
fi
|
|
done
|
|
;;
|
|
restart)
|
|
$0 stop
|
|
sleep 1
|
|
$0 start
|
|
;;
|
|
version)
|
|
for v in $ServiceList; do
|
|
if [ -x "$BinDir/$v" ]; then
|
|
$BinDir/$v --version
|
|
else
|
|
echo "$v binary not found in $BinDir"
|
|
fi
|
|
done
|
|
;;
|
|
*)
|
|
echo "OMC Service Control"
|
|
echo "Usage: $0 start|status|stop|restart|version"
|
|
echo ""
|
|
;;
|
|
esac
|