41 Star 466 Fork 179

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 "$@"
Go
1
https://gitee.com/sagoo-cloud/sagooiot.git
git@gitee.com:sagoo-cloud/sagooiot.git
sagoo-cloud
sagooiot
sagooiot
main

搜索帮助