forked from sjqzhang/go-fastdfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/bin/bash | ||
|
||
WORKSPACE=$(cd $(dirname $0)/; pwd) | ||
cd $WORKSPACE | ||
|
||
mkdir -p log conf | ||
|
||
module= | ||
app=fileserver | ||
conf=conf/cfg.json | ||
pidfile=conf/app.pid | ||
logfile=log/app.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 start() { | ||
check_pid | ||
running=$? | ||
if [ $running -gt 0 ];then | ||
echo -n "$app now is running already, pid=" | ||
cat $pidfile | ||
return 1 | ||
fi | ||
|
||
nohup ./$app &> $logfile & | ||
echo $! > $pidfile | ||
echo "$app started..., pid=$!" | ||
} | ||
|
||
function stop() { | ||
pid=`cat $pidfile` | ||
kill $pid | ||
echo "$app stoped..." | ||
} | ||
|
||
function restart() { | ||
stop | ||
sleep 1 | ||
start | ||
} | ||
|
||
function status() { | ||
check_pid | ||
running=$? | ||
if [ $running -gt 0 ];then | ||
echo -n "$app now is running, pid=" | ||
cat $pidfile | ||
else | ||
echo "$app is stoped" | ||
fi | ||
} | ||
|
||
function tailf() { | ||
tail -f $logfile | ||
} | ||
|
||
function build() { | ||
go build | ||
if [ $? -ne 0 ]; then | ||
exit $? | ||
fi | ||
mv $module $app | ||
./$app -v | grep -v "config" | ||
} | ||
|
||
function pack() { | ||
build | ||
git log -1 --pretty=%h > gitversion | ||
version=`./$app -v|grep -v config` | ||
file_list="control cfg.example.json $app" | ||
tar zcf $app-$version.tar.gz gitversion $file_list | ||
} | ||
|
||
function packbin() { | ||
build | ||
git log -1 --pretty=%h > gitversion | ||
version=`./$app -v|grep -v config` | ||
tar zcvf $app-bin-$version.tar.gz $app gitversion | ||
} | ||
|
||
function help() { | ||
echo "$0 start|stop|restart|status|tail" | ||
} | ||
|
||
if [ "$1" == "" ]; then | ||
help | ||
elif [ "$1" == "stop" ];then | ||
stop | ||
elif [ "$1" == "start" ];then | ||
start | ||
elif [ "$1" == "restart" ];then | ||
restart | ||
elif [ "$1" == "status" ];then | ||
status | ||
elif [ "$1" == "tail" ];then | ||
tailf | ||
else | ||
help | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters