Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-03-23 14:40:55 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7930add7f9810961691000e7a26fce1169d08202
7930add7
1 parent
b290a00d
add log tank config, default to console.
显示空白字符变更
内嵌
并排对比
正在显示
9 个修改的文件
包含
87 行增加
和
49 行删除
trunk/conf/full.conf
trunk/conf/srs.conf
trunk/etc/init.d/srs
trunk/src/app/srs_app_config.cpp
trunk/src/app/srs_app_config.hpp
trunk/src/app/srs_app_log.cpp
trunk/src/app/srs_app_server.cpp
trunk/src/app/srs_app_server.hpp
trunk/src/main/srs_main_server.cpp
trunk/conf/full.conf
查看文件 @
7930add
...
...
@@ -18,10 +18,11 @@ chunk_size 60000;
# if enabled ffmpeg, each stracoding stream will create a log file.
# default: ./objs/logs
ff_log_dir
./
objs
/
logs
;
# the log file for srs.
# if not specified or empty, disable log to file, only print to console.
# if speicfied, write log to file and print to console.
# default: empty.
# the log tank, console or file.
# if console, print log to console.
# if file, write log to file. requires srs_log_file if log to file.
# default: console.
srs_log_tank
console
;
srs_log_file
./
objs
/
srs
.
log
;
# the max connections.
# if exceed the max connections, server will drop the new connection.
...
...
trunk/conf/srs.conf
查看文件 @
7930add
...
...
@@ -2,6 +2,7 @@
# @see full.conf for detail config.
listen
1935
;
srs_log_tank
file
;
srs_log_file
./
objs
/
srs
.
log
;
vhost
__
defaultVhost__
{
}
...
...
trunk/etc/init.d/srs
查看文件 @
7930add
...
...
@@ -27,11 +27,11 @@ YELLOW="\\e[33m"
BLACK
=
"
\\
e[0m"
POS
=
"
\\
e[60G"
ok_msg
(){
ok_msg
()
{
echo
-e
"
${
1
}${
POS
}${
BLACK
}
[
${
GREEN
}
OK
${
BLACK
}
]"
}
failed_msg
(){
failed_msg
()
{
echo
-e
"
${
1
}${
POS
}${
BLACK
}
[
${
RED
}
FAILED
${
BLACK
}
]"
}
...
...
@@ -43,14 +43,14 @@ failed_msg(){
# @set variable $error_msg if error.
# @set variable $srs_pid_file to pid file.
load_process_info
()
{
# get pid file
srs_pid_file
=
`
cat
${
ROOT
}
/
${
CONFIG
}
|grep ^pid|awk
'{print $2}'
|awk -F
';'
'{print $1}'
`
if
[[
-z
$srs_pid_file
]]
;
then
srs_pid_file
=
${
DEFAULT_PID_FILE
}
;
fi
# get abs path
srs_pid_dir
=
`
dirname
$srs_pid_file
`
srs_pid_file
=
`
(
cd
${
ROOT
}
;
cd
$srs_pid_dir
;
pwd
)
`
/
`
basename
$srs_pid_file
`
if
[[
-f
$srs_pid_file
]]
;
then
srs_pid
=
`
cat
$srs_pid_file
2>/dev/null
`
else
srs_pid
=
`
cat
${
ROOT
}
/
$srs_pid_file
2>/dev/null
`
fi
ret
=
$?
;
if
[[
0 -ne
$ret
]]
;
then
error_msg
=
"file
$srs_pid_file
does not exists"
;
return
1;
fi
ps -p
${
srs_pid
}
>/dev/null 2>/dev/null
...
...
@@ -69,21 +69,24 @@ start() {
# get log file
srs_log_file
=
`
cat
${
ROOT
}
/
${
CONFIG
}
|grep
'^srs_log_file'
| awk
'{print $2}'
| awk -F
';'
'{print $1}'
`
if
[[
-z
$srs_log_file
]]
;
then
srs_log_file
=
${
DEFAULT_LOG_FILE
}
;
fi
# get abs path
srs_log_dir
=
`
dirname
$srs_log_file
`
srs_log_file
=
`
(
cd
${
ROOT
}
;
cd
$srs_log_dir
;
pwd
)
`
/
`
basename
$srs_log_file
`
# TODO: FIXME: set limit by, for instance, "ulimit -HSn 10000"
if
[[
-z
$srs_log_file
]]
;
then
(
cd
${
ROOT
}
;
${
APP
}
-c
${
CONFIG
}
>/dev/null 2>&1
)
(
cd
${
ROOT
}
;
${
ROOT
}
/
${
APP
}
-c
${
CONFIG
}
>/dev/null 2>&1
)
else
(
cd
${
ROOT
}
;
${
APP
}
-c
${
CONFIG
}
>>
$srs_log_file
2>&1
)
(
cd
${
ROOT
}
;
${
ROOT
}
/
${
APP
}
-c
${
CONFIG
}
>>
$srs_log_file
2>&1
)
fi
# check again after start server
sleep 1
for
((
i
=
0; i < 5; i++
))
;
do
# sleep a little while, for srs may start then crash.
sleep 0.1
load_process_info
ret
=
$?
;
if
[[
0 -ne
$ret
]]
;
then
failed_msg
"SRS start failed"
;
return
$ret
;
fi
ret
=
$?
;
if
[[
0 -ne
$ret
]]
;
then
failed_msg
"SRS start failed
, see
$srs_log_file
"
;
return
$ret
;
fi
done
# check whether started.
...
...
trunk/src/app/srs_app_config.cpp
查看文件 @
7930add
...
...
@@ -308,7 +308,7 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<string>& arg
srs_error
(
"line %d: unexpected end of file, expecting ; or
\"
}
\"
"
,
buffer
->
line
);
return
ERROR_SYSTEM_CONFIG_INVALID
;
}
srs_trace
(
"
end of file. ret=%d"
,
ret
);
srs_trace
(
"
config parsed EOF"
);
return
ret
;
}
...
...
@@ -684,7 +684,13 @@ int SrsConfig::parse_file(const char* filename)
// TODO: check http.
// TODO: check pid.
// check log
std
::
string
log_filename
=
this
->
get_srs_log_file
();
if
(
this
->
get_srs_log_tank_file
()
&&
log_filename
.
empty
())
{
ret
=
ERROR_SYSTEM_CONFIG_INVALID
;
srs_error
(
"must specifies the file to write log to. ret=%d"
,
ret
);
return
ret
;
}
if
(
!
log_filename
.
empty
())
{
srs_trace
(
"log file is %s"
,
log_filename
.
c_str
());
}
...
...
@@ -1282,6 +1288,18 @@ string SrsConfig::get_srs_log_file()
return
conf
->
arg0
();
}
bool
SrsConfig
::
get_srs_log_tank_file
()
{
srs_assert
(
root
);
SrsConfDirective
*
conf
=
root
->
get
(
"srs_log_tank"
);
if
(
conf
&&
conf
->
arg0
()
==
"file"
)
{
return
true
;
}
return
false
;
}
bool
SrsConfig
::
get_deamon
()
{
srs_assert
(
root
);
...
...
trunk/src/app/srs_app_config.hpp
查看文件 @
7930add
...
...
@@ -148,6 +148,7 @@ public:
virtual
void
get_engine_aparams
(
SrsConfDirective
*
engine
,
std
::
vector
<
std
::
string
>&
aparams
);
virtual
std
::
string
get_engine_output
(
SrsConfDirective
*
engine
);
virtual
std
::
string
get_ffmpeg_log_dir
();
virtual
bool
get_srs_log_tank_file
();
virtual
std
::
string
get_srs_log_file
();
virtual
bool
get_deamon
();
virtual
int
get_max_connections
();
...
...
trunk/src/app/srs_app_log.cpp
查看文件 @
7930add
...
...
@@ -42,7 +42,7 @@ SrsThreadContext::~SrsThreadContext()
void
SrsThreadContext
::
generate_id
()
{
static
int
id
=
1
;
static
int
id
=
1
00
;
cache
[
st_thread_self
()]
=
id
++
;
}
...
...
@@ -230,6 +230,7 @@ void SrsFastLog::write_log(char *str_log, int size, int _level)
log_data
[
size
++
]
=
LOG_TAIL
;
log_data
[
size
++
]
=
0
;
if
(
fd
<
0
||
!
_srs_config
->
get_srs_log_tank_file
())
{
// if is error msg, then print color msg.
// \033[31m : red text code in shell
// \033[32m : green text code in shell
...
...
@@ -242,8 +243,9 @@ void SrsFastLog::write_log(char *str_log, int size, int _level)
}
else
{
printf
(
"
\033
[31m%s
\033
[0m"
,
str_log
);
}
}
// open log file.
// open log file.
if specified
if
(
!
_srs_config
->
get_srs_log_file
().
empty
()
&&
fd
<
0
)
{
std
::
string
filename
=
_srs_config
->
get_srs_log_file
();
...
...
@@ -256,8 +258,9 @@ void SrsFastLog::write_log(char *str_log, int size, int _level)
);
}
}
// write log to file.
if
(
fd
>
0
)
{
if
(
fd
>
0
&&
_srs_config
->
get_srs_log_tank_file
()
)
{
::
write
(
fd
,
str_log
,
size
);
}
}
...
...
trunk/src/app/srs_app_server.cpp
查看文件 @
7930add
...
...
@@ -179,26 +179,6 @@ SrsServer::~SrsServer()
int
SrsServer
::
initialize
()
{
int
ret
=
ERROR_SUCCESS
;
// use linux epoll.
if
(
st_set_eventsys
(
ST_EVENTSYS_ALT
)
==
-
1
)
{
ret
=
ERROR_ST_SET_EPOLL
;
srs_error
(
"st_set_eventsys use linux epoll failed. ret=%d"
,
ret
);
return
ret
;
}
srs_verbose
(
"st_set_eventsys use linux epoll success"
);
if
(
st_init
()
!=
0
){
ret
=
ERROR_ST_INITIALIZE
;
srs_error
(
"st_init failed. ret=%d"
,
ret
);
return
ret
;
}
srs_verbose
(
"st_init success"
);
// set current log id.
_srs_context
->
generate_id
();
srs_info
(
"log set id success"
);
return
ret
;
}
...
...
@@ -277,6 +257,32 @@ int SrsServer::acquire_pid_file()
return
ret
;
}
int
SrsServer
::
initialize_st
()
{
int
ret
=
ERROR_SUCCESS
;
// use linux epoll.
if
(
st_set_eventsys
(
ST_EVENTSYS_ALT
)
==
-
1
)
{
ret
=
ERROR_ST_SET_EPOLL
;
srs_error
(
"st_set_eventsys use linux epoll failed. ret=%d"
,
ret
);
return
ret
;
}
srs_verbose
(
"st_set_eventsys use linux epoll success"
);
if
(
st_init
()
!=
0
){
ret
=
ERROR_ST_INITIALIZE
;
srs_error
(
"st_init failed. ret=%d"
,
ret
);
return
ret
;
}
srs_verbose
(
"st_init success"
);
// set current log id.
_srs_context
->
generate_id
();
srs_info
(
"log set id success"
);
return
ret
;
}
int
SrsServer
::
listen
()
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/app/srs_app_server.hpp
查看文件 @
7930add
...
...
@@ -80,6 +80,7 @@ public:
public
:
virtual
int
initialize
();
virtual
int
acquire_pid_file
();
virtual
int
initialize_st
();
virtual
int
listen
();
virtual
int
cycle
();
virtual
void
remove
(
SrsConnection
*
conn
);
...
...
trunk/src/main/srs_main_server.cpp
查看文件 @
7930add
...
...
@@ -61,17 +61,7 @@ int run_master()
signal
(
SIGTERM
,
handler
);
signal
(
SIGINT
,
handler
);
srs_trace
(
"uname: "
SRS_UNAME
);
srs_trace
(
"build: %s, %s"
,
SRS_BUILD_DATE
,
srs_is_little_endian
()
?
"little-endian"
:
"big-endian"
);
srs_trace
(
"configure: "
SRS_CONFIGURE
);
if
((
ret
=
_srs_server
->
initialize
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
// TODO: create log dir in _srs_config->get_log_dir()
if
((
ret
=
_srs_server
->
acquire_pid_file
())
!=
ERROR_SUCCESS
)
{
if
((
ret
=
_srs_server
->
initialize_st
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
@@ -137,6 +127,8 @@ int main(int argc, char** argv)
{
int
ret
=
ERROR_SUCCESS
;
srs_trace
(
"srs(simple-rtmp-server)"
);
// TODO: support both little and big endian.
srs_assert
(
srs_is_little_endian
());
...
...
@@ -161,5 +153,17 @@ int main(int argc, char** argv)
return
ret
;
}
srs_trace
(
"uname: "
SRS_UNAME
);
srs_trace
(
"build: %s, %s"
,
SRS_BUILD_DATE
,
srs_is_little_endian
()
?
"little-endian"
:
"big-endian"
);
srs_trace
(
"configure: "
SRS_CONFIGURE
);
if
((
ret
=
_srs_server
->
initialize
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
if
((
ret
=
_srs_server
->
acquire_pid_file
())
!=
ERROR_SUCCESS
)
{
return
ret
;
}
return
run
();
}
...
...
请
注册
或
登录
后发表评论