1 Star 3 Fork 2

zoutao98/python manage services script

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
service.sh 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
zoutao98 提交于 2023-09-13 09:54 . bash管理脚本
#!/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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zoutao98/services-script.git
[email protected]:zoutao98/services-script.git
zoutao98
services-script
python manage services script
main

搜索帮助