Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F7312140
sylk-server
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
sylk-server
View Options
#!/usr/bin/env python
# Copyright (C) 2010-2011 AG Projects. See LICENSE for details
#
import
os
import
signal
import
sys
from
optparse
import
OptionParser
from
application
import
log
from
application.process
import
process
,
ProcessError
from
sipsimple
import
__version__
as
sipsimple_version
import
sylk
def
main
():
name
=
'sylk-server'
fullname
=
'SylkServer'
runtime_directory
=
'/var/run/sylkserver'
system_config_directory
=
'/etc/sylkserver'
default_pid
=
os
.
path
.
join
(
runtime_directory
,
'server.pid'
)
default_config
=
sylk
.
configuration_filename
if
os
.
path
.
isfile
(
sylk
.
configuration_filename
)
else
os
.
path
.
join
(
system_config_directory
,
sylk
.
configuration_filename
)
parser
=
OptionParser
(
version
=
'
%%
prog
%s
'
%
sylk
.
__version__
)
parser
.
add_option
(
'--no-fork'
,
action
=
'store_false'
,
dest
=
'fork'
,
default
=
1
,
help
=
'run the process in the foreground (for debugging)'
)
parser
.
add_option
(
'--pid'
,
dest
=
'pid_file'
,
help
=
'pid file ("
%s
")'
%
default_pid
,
metavar
=
'File'
)
parser
.
add_option
(
'--config-file'
,
dest
=
'config_file'
,
default
=
default_config
,
help
=
'path to configuration file to read ("
%s
")'
%
default_config
,
metavar
=
'File'
)
parser
.
add_option
(
'--enable-bonjour'
,
action
=
'store_true'
,
dest
=
'enable_bonjour'
,
default
=
False
,
help
=
'enable Bonjour services'
)
parser
.
add_option
(
'--debug-memory'
,
action
=
'store_true'
,
dest
=
'debug_memory'
,
default
=
False
,
help
=
'enable memory debugging (works only if --no-fork is specified)'
)
(
options
,
args
)
=
parser
.
parse_args
()
path
,
configuration_filename
=
os
.
path
.
split
(
options
.
config_file
)
if
path
:
system_config_directory
=
path
process
.
system_config_directory
=
system_config_directory
sylk
.
configuration_filename
=
process
.
config_file
(
options
.
config_file
)
pid_file
=
options
.
pid_file
or
default_pid
# when run in foreground, do not require root access because of /var/run/sylkserver
if
not
options
.
fork
:
process
.
_runtime_directory
=
None
else
:
try
:
process
.
runtime_directory
=
runtime_directory
process
.
daemonize
(
pid_file
)
except
ProcessError
,
e
:
log
.
fatal
(
"Cannot start
%s
:
%s
"
%
(
fullname
,
e
))
sys
.
exit
(
1
)
log
.
start_syslog
(
name
)
if
sylk
.
configuration_filename
:
log
.
msg
(
"Starting
%s
%s
, config=
%s
"
%
(
fullname
,
sylk
.
__version__
,
sylk
.
configuration_filename
))
else
:
log
.
msg
(
"Starting
%s
%s
, with no configuration file"
%
(
fullname
,
sylk
.
__version__
))
log
.
msg
(
"Using SIP SIMPLE SDK version
%s
"
%
sipsimple_version
)
if
not
options
.
fork
and
options
.
debug_memory
:
from
application.debug.memory
import
memory_dump
from
sylk.server
import
SylkServer
server
=
SylkServer
()
def
stop_server
(
*
args
):
if
not
server
.
stopping_event
.
is_set
():
log
.
msg
(
'Stopping SylkServer...'
)
server
.
stop
()
process
.
signals
.
add_handler
(
signal
.
SIGTERM
,
stop_server
)
process
.
signals
.
add_handler
(
signal
.
SIGINT
,
stop_server
)
def
toggle_debugging
(
*
args
):
from
sylk.configuration
import
ServerConfig
if
log
.
level
.
current
!=
log
.
level
.
DEBUG
:
log
.
level
.
current
=
log
.
level
.
DEBUG
log
.
info
(
"Switched logging level to DEBUG"
)
else
:
log
.
info
(
"Switched logging level to {}"
.
format
(
ServerConfig
.
log_level
))
log
.
level
.
current
=
ServerConfig
.
log_level
process
.
signals
.
add_handler
(
signal
.
SIGUSR1
,
toggle_debugging
)
try
:
server
.
start
(
options
)
except
Exception
,
e
:
log
.
fatal
(
"failed to run
%s
:
%s
"
%
(
fullname
,
e
))
log
.
err
()
sys
.
exit
(
1
)
else
:
while
not
server
.
stopping_event
.
wait
(
9999
):
pass
server
.
stop_event
.
wait
(
5
)
if
server
.
stop_event
.
is_set
():
log
.
msg
(
"
%s
stopped"
%
fullname
)
else
:
log
.
msg
(
'Forcefully exiting SylkServer...'
)
os
.
_exit
(
1
)
if
not
options
.
fork
and
options
.
debug_memory
:
print
"---------------------"
memory_dump
()
print
"---------------------"
sys
.
exit
(
int
(
server
.
failed
))
if
__name__
==
"__main__"
:
main
()
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Sat, Feb 1, 5:11 AM (19 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3488719
Default Alt Text
sylk-server (4 KB)
Attached To
Mode
rSYLK SylkServer
Attached
Detach File
Event Timeline
Log In to Comment