mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
update scripts/cjserver
This commit is contained in:
parent
751da14611
commit
5b8345539e
@ -6,8 +6,14 @@ port=11200
|
|||||||
#number of thread
|
#number of thread
|
||||||
thread_num=4
|
thread_num=4
|
||||||
|
|
||||||
|
#deamonize
|
||||||
|
daemonize=true
|
||||||
|
|
||||||
#dict path
|
#dict path
|
||||||
dict_path=/usr/share/CppJieba/dicts/jieba.dict.utf8
|
dict_path=/usr/share/CppJieba/dicts/jieba.dict.utf8
|
||||||
|
|
||||||
#model path
|
#model path
|
||||||
model_path=/usr/share/CppJieba/dicts/hmm_model.utf8
|
model_path=/usr/share/CppJieba/dicts/hmm_model.utf8
|
||||||
|
|
||||||
|
#pid file
|
||||||
|
pid_file=/var/run/CppJieba/cjserver.pid
|
||||||
|
@ -8,6 +8,7 @@ DESC=cjserver
|
|||||||
|
|
||||||
RUNDIR=/var/run/CppJieba
|
RUNDIR=/var/run/CppJieba
|
||||||
PIDFILE=$RUNDIR/cjserver.pid
|
PIDFILE=$RUNDIR/cjserver.pid
|
||||||
|
LOGFILE=/dev/null
|
||||||
|
|
||||||
test -x $DAEMON || exit 0
|
test -x $DAEMON || exit 0
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ case "$1" in
|
|||||||
mkdir -p $RUNDIR
|
mkdir -p $RUNDIR
|
||||||
touch $PIDFILE
|
touch $PIDFILE
|
||||||
chmod 755 $RUNDIR
|
chmod 755 $RUNDIR
|
||||||
if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
|
if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --exec /bin/bash -- -c "$DAEMON $DAEMON_ARGS >> $LOGFILE 2>&1"
|
||||||
then
|
then
|
||||||
echo "$NAME."
|
echo "$NAME."
|
||||||
else
|
else
|
||||||
|
@ -76,6 +76,23 @@ bool run(int argc, char** argv)
|
|||||||
LogFatal("conf get model_path failed.");
|
LogFatal("conf get model_path failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(conf.get("daemonize", val) && "true" == val)
|
||||||
|
{
|
||||||
|
if(fork() > 0)
|
||||||
|
exit(0);
|
||||||
|
setsid();
|
||||||
|
if(!conf.get("pid_file", val))
|
||||||
|
{
|
||||||
|
LogFatal("conf get pid_file failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pid = getpid();
|
||||||
|
string pidStr = to_string(pid);
|
||||||
|
loadStr2File(val.c_str(), ios::out, pidStr);
|
||||||
|
LogInfo("write pid[%s] into file[%s]", pidStr.c_str(), val.c_str());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
ReqHandler reqHandler(dictPath, modelPath);
|
ReqHandler reqHandler(dictPath, modelPath);
|
||||||
ServerFrame sf(port, threadNum, &reqHandler);
|
ServerFrame sf(port, threadNum, &reqHandler);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user