Skip to content

Commit

Permalink
rewrite server script for cjserver
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyiwu committed Apr 11, 2014
1 parent 0d9008d commit 0af9ae3
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 90 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ make test
```
#Usage: /etc/init.d/cjserver {start|stop|restart|force-reload}
#启动
sudo /etc/init.d/cjserver start
/etc/init.d/cjserver.start
#停止
sudo /etc/init.d/cjserver stop
/etc/init.d/cjserver.stop
```

#### 测试服务
Expand Down
6 changes: 0 additions & 6 deletions conf/server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@
port=11200


#deamonize
daemonize=true

#dict path
dict_path=/usr/share/CppJieba/dict/jieba.dict.utf8

#model path
model_path=/usr/share/CppJieba/dict/hmm_model.utf8

#pid file
pid_file=/var/run/CppJieba/cjserver.pid
2 changes: 1 addition & 1 deletion script/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INSTALL(PROGRAMS cjserver DESTINATION /etc/init.d/)
INSTALL(PROGRAMS cjserver.start cjserver.stop DESTINATION /etc/init.d/)
INSTALL(PROGRAMS cjseg.sh DESTINATION bin)
63 changes: 0 additions & 63 deletions script/cjserver

This file was deleted.

10 changes: 10 additions & 0 deletions script/cjserver.start
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

PID=`pidof cjserver`
if [ ! -z "${PID}" ]
then
echo "please stop cjserver first."
else
cjserver /etc/CppJieba/server.conf &
echo "service startted."
fi
11 changes: 11 additions & 0 deletions script/cjserver.stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

PID=`pidof cjserver`
if [ ! -z "${PID}" ]
then
kill ${PID}
sleep 1
echo "service stop ok."
else
echo "cjserver is not running."
fi
18 changes: 0 additions & 18 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,6 @@ bool run(int argc, char** argv)
LogFatal("conf get model_path failed.");
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;
string_format(pidStr, "%d", 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);
EpollServer sf(port, &reqHandler);
Expand Down

0 comments on commit 0af9ae3

Please sign in to comment.