代码拉取完成,页面将自动刷新
#!/bin/bash
# Function to get the process ID of the application
getAppPid() {
app=$1
pid=$(ps -ef | grep "$app" | grep -v "grep\|$0" | awk '{print $2}')
echo "$pid"
}
# Function to start the application
startApp() {
app=$1
if [ -z "$app" ]; then
echo "Please provide the application name."
exit 1
fi
pid=$(getAppPid "$app")
if [ -n "$pid" ]; then
echo "Application is already running. PID: $pid"
exit 1
fi
nohup java -jar "$app" > /dev/null 2>&1 &
echo "Application started."
}
# Function to stop the application
stopApp() {
app=$1
if [ -z "$app" ]; then
echo "Please provide the application name."
exit 1
fi
pid=$(getAppPid "$app")
while [ -n "$pid" ]; do
kill "$pid"
echo "Application is still running."
sleep 1
pid=$(getAppPid "$app")
done
echo "Application stopped."
}
# Function to restart the application
restartApp() {
app=$1
if [ -z "$app" ]; then
echo "Please provide the application name."
exit 1
fi
stopApp "$app"
startApp "$app"
}
# Function to get the status of the application
getStatus() {
app=$1
if [ -z "$app" ]; then
echo "Please provide the application name."
exit 1
fi
pid=$(getAppPid "$app")
if [ -n "$pid" ]; then
echo "Application is running. PID: $pid"
else
echo "Application is not running."
fi
}
# Parse command line arguments
app="$1"
operation="$2"
case $operation in
start|1)
startApp "$app"
;;
stop|2)
stopApp "$app"
;;
restart|3)
restartApp "$app"
;;
status)
getStatus "$app"
;;
*)
echo "Invalid operation" "$1" "$2"
exit 1
;;
esac
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。