1 Star 0 Fork 192

北京奥技异电气技术研究所有限公司/sagooiot

forked from sagoo/sagooiot 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
curl.sh 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
#!/bin/bash
WORKSPACE=$(cd "$(dirname "$0")" || exit; pwd)
cd "$WORKSPACE" || exit
readonly app='sagooiot'
readonly pidfile="var/$app.pid"
readonly logfile="var/$app.log"
mkdir -p var
check_pid() {
if [[ -f $pidfile ]]; then
local pid=$(cat "$pidfile")
if [[ -n $pid ]]; then
local running=$(ps -p "$pid" | grep -c -v "PID TTY")
return "$running"
fi
fi
return 0
}
start() {
check_pid
local running=$?
if [[ $running -gt 0 ]]; then
printf "%s now is running already, pid: %s\n" "$app" "$(cat "$pidfile")"
return 1
fi
nohup "./$app" >> "$logfile" 2>&1 &
sleep 1
running=$(ps -p $! | grep -c -v "PID TTY")
if [[ $running -gt 0 ]]; then
echo $! > "$pidfile"
printf "%s started... pid: %s\n" "$app" "$!"
else
printf "%s failed to start.\n" "$app"
return 1
fi
}
stop() {
check_pid
local running=$?
if [[ $running -gt 0 ]]; then
local pid=$(cat "$pidfile")
kill "$pid"
rm -f "$pidfile"
printf "%s stopped.\n" "$app"
else
printf "%s is not running.\n" "$app"
fi
}
restart() {
stop
sleep 1
start
}
status() {
check_pid
local running=$?
if [[ $running -gt 0 ]]; then
printf "%s is started.\n" "$app"
else
printf "%s is stopped.\n" "$app"
fi
}
tailf() {
tail -f var/*
}
print_help() {
printf "Usage: %s {start|stop|restart|status|tail|pid}.\n" "$0"
}
print_pid() {
cat "$pidfile"
}
main() {
case "$1" in
"start") start ;;
"stop") stop ;;
"restart") restart ;;
"status") status ;;
"tail") tailf ;;
"pid") print_pid ;;
*) print_help ;;
esac
}
main "$@"
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/orientge/sagooiot.git
git@gitee.com:orientge/sagooiot.git
orientge
sagooiot
sagooiot
main

搜索帮助