Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cloudooo
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
cloudooo
Commits
a23689c5
Commit
a23689c5
authored
May 29, 2019
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support libreoffice lockfile
parent
78c4ce1b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
1 deletion
+55
-1
cloudooo/handler/ooo/application/openoffice.py
cloudooo/handler/ooo/application/openoffice.py
+16
-1
cloudooo/handler/ooo/util.py
cloudooo/handler/ooo/util.py
+39
-0
No files found.
cloudooo/handler/ooo/application/openoffice.py
View file @
a23689c5
...
@@ -34,8 +34,11 @@ from zope.interface import implements
...
@@ -34,8 +34,11 @@ from zope.interface import implements
from
application
import
Application
from
application
import
Application
from
cloudooo.interfaces.lockable
import
ILockable
from
cloudooo.interfaces.lockable
import
ILockable
from
cloudooo.util
import
logger
from
cloudooo.util
import
logger
import
signal
from
cloudooo.handler.ooo.util
import
waitStartDaemon
,
\
from
cloudooo.handler.ooo.util
import
waitStartDaemon
,
\
removeDirectory
removeDirectory
,
\
processUsedFilesInPath
,
\
kill_procs_tree
try
:
try
:
import
json
import
json
except
ImportError
:
except
ImportError
:
...
@@ -139,6 +142,18 @@ class OpenOffice(Application):
...
@@ -139,6 +142,18 @@ class OpenOffice(Application):
"""Start Instance."""
"""Start Instance."""
self
.
path_user_installation
=
join
(
self
.
path_run_dir
,
\
self
.
path_user_installation
=
join
(
self
.
path_run_dir
,
\
"cloudooo_instance_%s"
%
self
.
port
)
"cloudooo_instance_%s"
%
self
.
port
)
lock_file
=
join
(
self
.
path_user_installation
,
'.lock'
)
if
exists
(
lock_file
):
pids
=
processUsedFilesInPath
(
self
.
path_user_installation
)
if
len
(
pids
)
==
0
:
logger
.
debug
(
"Stalled lock file: %s"
,
lock_file
)
else
:
logger
.
debug
(
"kill process used workdir: %s"
,
self
.
path_user_installation
)
_
,
alive
=
kill_procs_tree
(
pids
,
sig
=
signal
.
SIGKILL
,
timeout
=
self
.
timeout
)
if
len
(
alive
)
>
0
:
logger
.
error
(
"process blocks worked directory and alive after SIGKILL: %s"
,
alive
)
removeDirectory
(
self
.
path_user_installation
)
if
init
and
exists
(
self
.
path_user_installation
):
if
init
and
exists
(
self
.
path_user_installation
):
removeDirectory
(
self
.
path_user_installation
)
removeDirectory
(
self
.
path_user_installation
)
# Create command with all parameters to start the instance
# Create command with all parameters to start the instance
...
...
cloudooo/handler/ooo/util.py
View file @
a23689c5
...
@@ -26,10 +26,13 @@
...
@@ -26,10 +26,13 @@
#
#
##############################################################################
##############################################################################
import
os
from
time
import
sleep
from
time
import
sleep
from
os
import
remove
from
os
import
remove
from
shutil
import
rmtree
from
shutil
import
rmtree
from
cloudooo.util
import
logger
from
cloudooo.util
import
logger
from
psutil
import
process_iter
,
Process
,
NoSuchProcess
,
wait_procs
import
signal
def
removeDirectory
(
path
):
def
removeDirectory
(
path
):
...
@@ -58,6 +61,42 @@ def waitStopDaemon(daemon, attempts=5):
...
@@ -58,6 +61,42 @@ def waitStopDaemon(daemon, attempts=5):
sleep
(
1
)
sleep
(
1
)
return
False
return
False
def
processUsedFilesInPath
(
path
):
pids
=
set
()
for
p
in
process_iter
(
attrs
=
[
'open_files'
,
'memory_maps'
]):
for
f
in
(
p
.
info
[
'open_files'
]
or
[])
+
(
p
.
info
[
'memory_maps'
]
or
[]):
if
f
.
path
.
startswith
(
path
):
pids
.
add
(
p
.
pid
)
return
pids
def
kill_procs_tree
(
pids
,
sig
=
signal
.
SIGTERM
,
timeout
=
3
,
on_terminate
=
None
):
pids
=
set
(
pids
)
children_pids
=
set
(
pids
)
for
pid
in
pids
:
parent
=
None
try
:
parent
=
Process
(
pid
)
except
NoSuchProcess
:
pass
if
parent
:
children
=
parent
.
children
(
recursive
=
True
)
for
p
in
children
:
children_pids
.
add
(
p
.
pid
)
my_pid
=
os
.
getpid
()
if
my_pid
in
children_pids
:
children_pids
.
remove
(
my_pid
)
pids
=
[]
for
pid
in
children_pids
:
try
:
p
=
Process
(
pid
)
p
.
send_signal
(
sig
)
pids
.
append
(
p
)
except
NoSuchProcess
:
pass
gone
,
alive
=
wait_procs
(
pids
,
timeout
=
timeout
,
callback
=
on_terminate
)
return
(
gone
,
alive
)
def
remove_file
(
filepath
):
def
remove_file
(
filepath
):
try
:
try
:
...
...
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