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
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
Stephane VAROQUI
slapos
Commits
15642ba1
Commit
15642ba1
authored
Aug 29, 2013
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
librecipe: add pidfile option for singletons.
parent
5afd81f9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
1 deletion
+21
-1
slapos/recipe/librecipe/generic.py
slapos/recipe/librecipe/generic.py
+21
-1
No files found.
slapos/recipe/librecipe/generic.py
View file @
15642ba1
...
...
@@ -33,6 +33,7 @@ import sys
import
inspect
import
re
import
shutil
from
textwrap
import
dedent
import
urllib
import
urlparse
...
...
@@ -129,10 +130,14 @@ class GenericBaseRecipe(object):
return
script
def
createWrapper
(
self
,
name
,
command
,
parameters
,
comments
=
[],
parameters_extra
=
False
,
environment
=
None
):
parameters_extra
=
False
,
environment
=
None
,
pidfile
=
None
):
"""
Creates a very simple (one command) shell script for process replacement.
Takes care of quoting.
if pidfile parameter is specified, then it will make the wrapper a singleton,
accepting to run only if no other instance is running.
"""
lines
=
[
'#!/bin/sh'
]
...
...
@@ -144,6 +149,21 @@ class GenericBaseRecipe(object):
for
key
in
environment
:
lines
.
append
(
'export %s=%s'
%
(
key
,
environment
[
key
]))
if
pidfile
:
lines
.
append
(
dedent
(
"""
\
# Check for other instances
pidfile=%s
if [ -e $pidfile ]; then
pid=$(cat $pidfile)
if [[ ! -z $(ps -p "$pid" | grep $(basename %s)) ]]; then
echo "Already running with pid $pid."
exit 1
else
rm $pidfile
fi
fi
echo $$ > $pidfile"""
%
(
pidfile
,
command
)))
lines
.
append
(
'exec %s'
%
shlex
.
quote
(
command
))
for
param
in
parameters
:
...
...
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