Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kwabena Antwi-Boasiako
slapos
Commits
d2e8a850
Commit
d2e8a850
authored
Apr 11, 2017
by
Tomáš Peterka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cookbook.wrapper: Add options remove_pidfile and cleanup_command
parent
3d31bf86
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
slapos/recipe/librecipe/generic.py
slapos/recipe/librecipe/generic.py
+22
-2
slapos/recipe/wrapper.py
slapos/recipe/wrapper.py
+6
-0
No files found.
slapos/recipe/librecipe/generic.py
View file @
d2e8a850
...
@@ -130,8 +130,8 @@ class GenericBaseRecipe(object):
...
@@ -130,8 +130,8 @@ class GenericBaseRecipe(object):
return
script
return
script
def
createWrapper
(
self
,
name
,
command
,
parameters
,
comments
=
[],
def
createWrapper
(
self
,
name
,
command
,
parameters
,
comments
=
[],
parameters_extra
=
False
,
environment
=
None
,
parameters_extra
=
False
,
environment
=
None
,
cleanup_command
=
None
,
pidfile
=
None
pidfile
=
None
,
remove_pidfile
=
False
):
):
"""
"""
Creates a shell script for process replacement.
Creates a shell script for process replacement.
...
@@ -139,6 +139,9 @@ class GenericBaseRecipe(object):
...
@@ -139,6 +139,9 @@ class GenericBaseRecipe(object):
Takes care of #! line limitation when the wrapped command is a script.
Takes care of #! line limitation when the wrapped command is a script.
if pidfile parameter is specified, then it will make the wrapper a singleton,
if pidfile parameter is specified, then it will make the wrapper a singleton,
accepting to run only if no other instance is running.
accepting to run only if no other instance is running.
:param remove_pidfile: remove pidfile when the script ends
:param cleanup_command: arbitrary cleanup command being run when the script ends
"""
"""
lines
=
[
'#!/bin/sh'
]
lines
=
[
'#!/bin/sh'
]
...
@@ -163,6 +166,22 @@ class GenericBaseRecipe(object):
...
@@ -163,6 +166,22 @@ class GenericBaseRecipe(object):
fi
fi
echo $$ > $pidfile"""
%
shlex
.
quote
(
pidfile
)))
echo $$ > $pidfile"""
%
shlex
.
quote
(
pidfile
)))
endlines
=
[]
if
cleanup_command
:
endlines
.
append
(
shlex
.
quote
(
cleanup_command
))
if
pidfile
and
remove_pidfile
:
endlines
.
append
(
"rm -f $pidfile"
)
if
endlines
:
endlines
.
insert
(
0
,
"function cleanUp {"
)
endlines
.
extend
((
"exit 0"
,
"}"
,
"trap cleanUp INT TERM KILL"
,
""
))
lines
.
extend
(
endlines
)
lines
.
append
(
dedent
(
'''
lines
.
append
(
dedent
(
'''
# If the wrapped command uses a shebang, execute the referenced
# If the wrapped command uses a shebang, execute the referenced
# executable passing the script path as first argument.
# executable passing the script path as first argument.
...
@@ -185,6 +204,7 @@ class GenericBaseRecipe(object):
...
@@ -185,6 +204,7 @@ class GenericBaseRecipe(object):
lines
.
append
(
'
\
t
'
+
param
)
lines
.
append
(
'
\
t
'
+
param
)
lines
.
append
(
''
)
lines
.
append
(
''
)
return
self
.
createFile
(
name
,
'
\
n
'
.
join
(
lines
),
0700
)
return
self
.
createFile
(
name
,
'
\
n
'
.
join
(
lines
),
0700
)
def
createDirectory
(
self
,
parent
,
name
,
mode
=
0700
):
def
createDirectory
(
self
,
parent
,
name
,
mode
=
0700
):
...
...
slapos/recipe/wrapper.py
View file @
d2e8a850
...
@@ -38,6 +38,8 @@ class Recipe(GenericBaseRecipe):
...
@@ -38,6 +38,8 @@ class Recipe(GenericBaseRecipe):
environment
=
self
.
options
.
get
(
'environment'
)
environment
=
self
.
options
.
get
(
'environment'
)
parameters_extra
=
self
.
options
.
get
(
'parameters-extra'
)
parameters_extra
=
self
.
options
.
get
(
'parameters-extra'
)
pidfile
=
self
.
options
.
get
(
'pidfile'
)
pidfile
=
self
.
options
.
get
(
'pidfile'
)
remove_pidfile
=
self
.
options
.
get
(
'remove_pidfile'
,
false
)
cleanup_command
=
self
.
options
.
get
(
'cleanup_command'
)
if
not
wait_files
and
not
environment
:
if
not
wait_files
and
not
environment
:
# Create a simple wrapper as shell script
# Create a simple wrapper as shell script
...
@@ -47,6 +49,8 @@ class Recipe(GenericBaseRecipe):
...
@@ -47,6 +49,8 @@ class Recipe(GenericBaseRecipe):
parameters
=
command_line
[
1
:],
parameters
=
command_line
[
1
:],
parameters_extra
=
parameters_extra
,
parameters_extra
=
parameters_extra
,
pidfile
=
pidfile
,
pidfile
=
pidfile
,
remove_pidfile
=
remove_pidfile
,
cleanup_command
=
cleanup_command
)]
)]
# More complex needs: create a Python script as wrapper
# More complex needs: create a Python script as wrapper
...
@@ -76,5 +80,7 @@ class Recipe(GenericBaseRecipe):
...
@@ -76,5 +80,7 @@ class Recipe(GenericBaseRecipe):
parameters
=
[],
parameters
=
[],
parameters_extra
=
parameters_extra
,
parameters_extra
=
parameters_extra
,
pidfile
=
pidfile
,
pidfile
=
pidfile
,
remove_pidfile
=
remove_pidfile
,
cleanup_command
=
cleanup_command
)]
)]
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