Fetch the repository succeeded.
This action will force synchronization from 暗夜之家/gopub, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
#!/bin/bash -e
export GOROOT=/usr/local/go
export PATH=$PATH:/usr/local/go/bin/
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BASENAME=`basename $DIR`
export GOPATH=$DIR
export GOBIN=$DIR/bin/
app=$BASENAME
conf=src/conf/app.conf
pidfile=$DIR/$BASENAME.pid
logfile=$DIR/$BASENAME.log
function check_pid() {
if [ -f $pidfile ];then
pid=`cat $pidfile`
if [ -n $pid ]; then
running=`ps -p $pid|grep -v "PID TTY" |wc -l`
return $running
fi
fi
return 0
}
function build() {
gofmt -w src/
cd src/
go build -o $BASENAME
if [ $? -ne 0 ]; then
exit $?
fi
}
function pack() {
build
cd $DIR
rm -rf src/logs && rm -rf src/cache
tar zcvf $app.tar.gz control src/$app src/conf src/views src/swagger src/logs src/cache
}
function start() {
check_pid
running=$?
if [ $running -gt 0 ];then
echo -n "$app now is running already, pid="
cat $pidfile
return 1
fi
if ! [ -f $conf ];then
echo "Config file $conf doesn't exist, creating one."
fi
cd src/
nohup ./$BASENAME >$logfile 2>&1 &
sleep 1
running=`ps -p $! | grep -v "PID TTY" | wc -l`
if [ $running -gt 0 ];then
echo $! > $pidfile
echo "$app started..., pid=$!"
else
echo "$app failed to start."
return 1
fi
}
function killall() {
pid=`cat $pidfile`
ps -ef|grep $BASENAME|grep -v grep|awk '{print $2}'|xargs kill -9
rm -f $pidfile
echo "$app killed..., pid=$pid"
}
function stop() {
#ps -ef|grep $BASENAME|grep -v grep|awk '{print $2}'|xargs kill -9
pid=`cat $pidfile`
kill $pid
rm -f $pidfile
echo "$app stoped..., pid=$pid"
}
function restart() {
stop
sleep 1
start
}
function reload() {
pid=`cat $pidfile`
kill -HUP $pid
sleep 1
newpid=`ps -ef|grep $BASENAME|grep -v grep|awk '{print $2}'`
echo "$app reload..., pid=$newpid"
echo $newpid > $pidfile
}
function status() {
check_pid
running=$?
if [ $running -gt 0 ];then
echo started
else
echo stoped
fi
}
function run() {
cd src/
./$BASENAME -docker
#go run main.go
}
function rundocker() {
cd src/
./$BASENAME -docker
#go run main.go
}
function init() {
cd src/
./$BASENAME -syncdb
#go run main.go
}
function beerun() {
cd src/
bee run
}
function tailf() {
tail -f $logfile
}
function docs() {
cd src/
bee generate docs
}
function sslkey() {
cd src/conf/ssl
###CA:
#私钥文件
openssl genrsa -out ca.key 2048
}
function help() {
echo "$0 build|start|stop|kill|restart|reload|run|rundocker|init|tail|docs|pack|beerun|sslkey"
}
if [ "$1" == "" ]; then
help
elif [ "$1" == "build" ];then
build
elif [ "$1" == "pack" ];then
pack
elif [ "$1" == "start" ];then
start
elif [ "$1" == "stop" ];then
stop
elif [ "$1" == "kill" ];then
killall
elif [ "$1" == "restart" ];then
restart
elif [ "$1" == "reload" ];then
reload
elif [ "$1" == "status" ];then
status
elif [ "$1" == "run" ];then
run
elif [ "$1" == "rundocker" ];then
rundocker
elif [ "$1" == "init" ];then
init
elif [ "$1" == "beerun" ];then
beerun
elif [ "$1" == "tail" ];then
tailf
elif [ "$1" == "docs" ];then
docs
elif [ "$1" == "sslkey" ];then
sslkey
else
help
fi
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。