Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cc-node
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
cc-node
Commits
fc74c9dc
Commit
fc74c9dc
authored
12 years ago
by
Anael Beutot
Browse files
Options
Downloads
Patches
Plain Diff
Rewrite binary.
parent
5a57e4d2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/cc-node
+3
-72
3 additions, 72 deletions
bin/cc-node
with
3 additions
and
72 deletions
bin/cc-node
+
3
−
72
View file @
fc74c9dc
#!/usr/bin/env python
#!/usr/bin/env python
import
sys
import
sys
import
signal
import
atexit
import
atexit
import
time
import
logging
import
logging.config
from
optparse
import
OptionParser
from
optparse
import
OptionParser
from
os.path
import
isfile
,
abspath
from
os.path
import
isfile
,
abspath
from
daemon
import
DaemonContext
from
daemon
import
DaemonContext
from
ccnode
import
__version__
from
ccnode
import
__version__
from
ccnode.node
import
Node
from
ccnode.node
import
MainLoop
from
ccnode.utils
import
signal_
from
ccnode.config
import
NodeConfigParser
logger
=
logging
.
getLogger
(
'
ccnode
'
)
DEFAULT_CONFIG_FILE
=
'
/etc/cc-node.conf
'
DEFAULT_CONFIG_FILE
=
'
/etc/cc-node.conf
'
...
@@ -33,6 +24,7 @@ oparser.add_option('-c', '--config', metavar='FILE',
...
@@ -33,6 +24,7 @@ oparser.add_option('-c', '--config', metavar='FILE',
oparser
.
add_option
(
'
-p
'
,
'
--pidfile
'
,
metavar
=
'
FILE
'
,
oparser
.
add_option
(
'
-p
'
,
'
--pidfile
'
,
metavar
=
'
FILE
'
,
help
=
u
'
pid file path for daemon mode
'
)
help
=
u
'
pid file path for daemon mode
'
)
options
,
args
=
oparser
.
parse_args
()
options
,
args
=
oparser
.
parse_args
()
# check argument configuration
# check argument configuration
if
options
.
daemonize
and
not
options
.
pidfile
:
if
options
.
daemonize
and
not
options
.
pidfile
:
sys
.
exit
(
u
'
Please supply a pid file...
'
)
sys
.
exit
(
u
'
Please supply a pid file...
'
)
...
@@ -42,59 +34,6 @@ if not isfile(options.config):
...
@@ -42,59 +34,6 @@ if not isfile(options.config):
sys
.
exit
(
u
'
Please supply a valid path to configuration file...
'
)
sys
.
exit
(
u
'
Please supply a valid path to configuration file...
'
)
# globals
need_reload
=
False
node
=
None
config_file
=
NodeConfigParser
(
options
.
config
)
# configure logging
logging
.
config
.
fileConfig
(
options
.
config
)
@signal_
(
signal
.
SIGUSR1
)
def
reload_config
(
signum
,
frame
):
global
need_reload
need_reload
=
True
@signal_
(
signal
.
SIGTERM
)
def
exit_node
(
signum
=
None
,
frame
=
None
):
# clean all current jobs
# TODO
if
node
is
not
None
:
# clean node
node
.
shutdown
()
# exit
logger
.
info
(
u
'
Exiting node...
'
)
sys
.
exit
()
def
run_node
():
global
need_reload
,
node
try
:
node
=
Node
(
server_host
=
config_file
.
server_host
,
server_port
=
config_file
.
server_port
,
user_name
=
config_file
.
server_user
,
user_passwd
=
config_file
.
server_passwd
,
)
node
.
start
()
while
True
:
if
need_reload
:
logger
.
info
(
u
'
Reloading logging configuration...
'
)
logging
.
config
.
fileConfig
(
options
.
config
)
need_reload
=
False
signal
.
pause
()
except
KeyboardInterrupt
:
exit_node
()
except
Exception
:
logger
.
exception
(
u
'
Unknown error:
'
)
# take care of pid file if daemon
# take care of pid file if daemon
if
options
.
daemonize
:
if
options
.
daemonize
:
pidfile
=
open
(
options
.
pidfile
)
pidfile
=
open
(
options
.
pidfile
)
...
@@ -102,13 +41,10 @@ if options.daemonize:
...
@@ -102,13 +41,10 @@ if options.daemonize:
else
:
else
:
files_preserve
=
None
files_preserve
=
None
with
DaemonContext
(
detach_process
=
options
.
daemonize
,
with
DaemonContext
(
detach_process
=
options
.
daemonize
,
files_preserve
=
files_preserve
,
files_preserve
=
files_preserve
,
stderr
=
sys
.
stderr
,
stderr
=
sys
.
stderr
,
stdout
=
sys
.
stdout
):
stdout
=
sys
.
stdout
):
# reload log config
logging
.
config
.
fileConfig
(
options
.
config
)
# take care of pidfile
# take care of pidfile
if
options
.
daemonize
:
if
options
.
daemonize
:
...
@@ -121,9 +57,4 @@ with DaemonContext(detach_process=options.daemonize,
...
@@ -121,9 +57,4 @@ with DaemonContext(detach_process=options.daemonize,
pidfile
.
truncate
()
pidfile
.
truncate
()
pidfile
.
flush
()
pidfile
.
flush
()
logger
.
debug
(
u
'
Starting node
'
)
MainLoop
(
options
.
config
).
start
()
while
True
:
run_node
()
logger
.
critical
(
u
'
Restarting node...
'
)
time
.
sleep
(
2
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment