Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pim_dm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
pim_dm
Commits
dd3e14f8
Commit
dd3e14f8
authored
Jun 26, 2017
by
Pedro Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed argparser -> requires one argument
parent
f91a2e1a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
34 deletions
+41
-34
Daemon/Daemon.py
Daemon/Daemon.py
+18
-11
Run.py
Run.py
+23
-23
No files found.
Daemon/Daemon.py
View file @
dd3e14f8
...
...
@@ -63,14 +63,7 @@ class Daemon:
"""Start the Daemon."""
# Check for a pidfile to see if the Daemon already runs
try
:
with
open
(
self
.
pidfile
,
'r'
)
as
pf
:
pid
=
int
(
pf
.
read
().
strip
())
except
IOError
:
pid
=
None
if
pid
:
if
self
.
is_running
():
message
=
"pidfile {0} already exist. "
+
\
"Daemon already running?
\
n
"
sys
.
stderr
.
write
(
message
.
format
(
self
.
pidfile
))
...
...
@@ -78,7 +71,6 @@ class Daemon:
# Start the Daemon
self
.
daemonize
()
print
(
"daemonize"
)
self
.
run
()
def
stop
(
self
):
...
...
@@ -86,7 +78,7 @@ class Daemon:
# Get the pid from the pidfile
try
:
with
open
(
self
.
pidfile
,
'r'
)
as
pf
:
with
open
(
self
.
pidfile
,
'r'
)
as
pf
:
pid
=
int
(
pf
.
read
().
strip
())
except
IOError
:
pid
=
None
...
...
@@ -120,4 +112,19 @@ class Daemon:
"""You should override this method when you subclass Daemon.
It will be called after the process has been daemonized by
start() or restart()."""
\ No newline at end of file
start() or restart()."""
def
is_running
(
self
):
try
:
with
open
(
self
.
pidfile
,
'r'
)
as
pf
:
pid
=
int
(
pf
.
read
().
strip
())
except
IOError
:
return
False
""" Check For the existence of a unix pid. """
try
:
os
.
kill
(
pid
,
0
)
except
OSError
:
return
False
else
:
return
True
Run.py
View file @
dd3e14f8
...
...
@@ -10,11 +10,15 @@ import argparse
class
MyDaemon
(
Daemon
):
def
stop
(
self
):
print
(
"stopping..."
)
# TODO: remove all interfaces
super
(
MyDaemon
,
self
).
stop
()
def
run
(
self
):
Main
.
main
()
server_address
=
'./uds_socket'
# Make sure the socket does not already exist
try
:
os
.
unlink
(
server_address
)
...
...
@@ -43,10 +47,10 @@ class MyDaemon(Daemon):
connection
.
sendall
(
pickle
.
dumps
(
Main
.
list_neighbors
()))
elif
args
.
add_interface
:
Main
.
add_interface
(
args
.
add_interface
[
0
])
connection
.
s
endall
(
pickle
.
dumps
(
''
)
)
connection
.
s
hutdown
(
socket
.
SHUT_RDWR
)
elif
args
.
remove_interface
:
Main
.
remove_interface
(
args
.
remove_interface
[
0
])
connection
.
s
endall
(
pickle
.
dumps
(
''
)
)
connection
.
s
hutdown
(
socket
.
SHUT_RDWR
)
finally
:
# Clean up the connection
connection
.
close
()
...
...
@@ -54,22 +58,15 @@ class MyDaemon(Daemon):
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
(
description
=
'PIM'
)
parser
.
add_argument
(
"-li"
,
"--list_interfaces"
,
action
=
"store_true"
,
default
=
False
,
help
=
"List All PIM Interfaces"
)
parser
.
add_argument
(
"-ln"
,
"--list_neighbors"
,
action
=
"store_true"
,
default
=
False
,
help
=
"List All PIM Neighbors"
)
parser
.
add_argument
(
"-ai"
,
"--add_interface"
,
nargs
=
1
,
help
=
"Add PIM interface"
)
parser
.
add_argument
(
"-ri"
,
"--remove_interface"
,
nargs
=
1
,
help
=
"Remove PIM interface"
)
parser
.
add_argument
(
"-start"
,
"--start"
,
action
=
"store_true"
,
default
=
False
,
help
=
"Start PIM"
)
parser
.
add_argument
(
"-stop"
,
"--stop"
,
action
=
"store_true"
,
default
=
False
,
help
=
"Stop PIM"
)
parser
.
add_argument
(
"-restart"
,
"--restart"
,
action
=
"store_true"
,
default
=
False
,
help
=
"Restart PIM"
)
parser
.
add_argument
(
"-v"
,
"--verbose"
,
action
=
"store_true"
,
default
=
False
,
help
=
"Verbose (print all debug messages)"
)
group
=
parser
.
add_mutually_exclusive_group
(
required
=
True
)
group
.
add_argument
(
"-start"
,
"--start"
,
action
=
"store_true"
,
default
=
False
,
help
=
"Start PIM"
)
group
.
add_argument
(
"-stop"
,
"--stop"
,
action
=
"store_true"
,
default
=
False
,
help
=
"Stop PIM"
)
group
.
add_argument
(
"-restart"
,
"--restart"
,
action
=
"store_true"
,
default
=
False
,
help
=
"Restart PIM"
)
group
.
add_argument
(
"-li"
,
"--list_interfaces"
,
action
=
"store_true"
,
default
=
False
,
help
=
"List All PIM Interfaces"
)
group
.
add_argument
(
"-ln"
,
"--list_neighbors"
,
action
=
"store_true"
,
default
=
False
,
help
=
"List All PIM Neighbors"
)
group
.
add_argument
(
"-ai"
,
"--add_interface"
,
nargs
=
1
,
metavar
=
'IP_INTERFACE'
,
help
=
"Add PIM interface"
)
group
.
add_argument
(
"-ri"
,
"--remove_interface"
,
nargs
=
1
,
metavar
=
'IP_INTERFACE'
,
help
=
"Remove PIM interface"
)
group
.
add_argument
(
"-v"
,
"--verbose"
,
action
=
"store_true"
,
default
=
False
,
help
=
"Verbose (print all debug messages)"
)
args
=
parser
.
parse_args
()
print
(
parser
.
parse_args
())
...
...
@@ -78,7 +75,6 @@ if __name__ == "__main__":
if
args
.
start
:
print
(
"start"
)
daemon
.
start
()
print
(
"start"
)
sys
.
exit
(
0
)
elif
args
.
stop
:
daemon
.
stop
()
...
...
@@ -89,6 +85,10 @@ if __name__ == "__main__":
elif
args
.
verbose
:
os
.
system
(
"tailf stdout"
)
sys
.
exit
(
0
)
elif
not
daemon
.
is_running
():
print
(
"PIM is not running"
)
parser
.
print_usage
()
sys
.
exit
(
0
)
# Create a UDS socket
...
...
@@ -99,7 +99,7 @@ if __name__ == "__main__":
print
(
'connecting to %s'
%
server_address
)
try
:
sock
.
connect
(
server_address
)
except
(
socket
.
error
)
:
except
socket
.
error
:
print
(
"erro socket"
)
print
(
sys
.
stderr
)
sys
.
exit
(
1
)
...
...
@@ -108,8 +108,8 @@ if __name__ == "__main__":
sock
.
sendall
(
pickle
.
dumps
(
args
))
data
=
sock
.
recv
(
1024
*
256
)
print
(
pickle
.
loads
(
data
))
if
data
:
print
(
pickle
.
loads
(
data
))
finally
:
print
(
'closing socket'
)
sock
.
close
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment