Skip to content

Commit 07f3f87

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
commands: add ability to wait for ctdb when running smbd/winbindd
Add a `--wait-for=ctdb` option to the `samba-container run` subcommand. This option will make sambacc wait for the condition, ctdb available and returning a valid pnn, to be true before starting the server. Signed-off-by: John Mulligan <[email protected]>
1 parent 0fde0a7 commit 07f3f87

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

sambacc/commands/run.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>
1717
#
1818

19+
import logging
20+
import time
21+
1922
from sambacc import samba_cmds
2023
import sambacc.paths as paths
2124

@@ -24,7 +27,34 @@
2427
from .join import join
2528

2629

30+
_logger = logging.getLogger(__name__)
31+
2732
INIT_ALL = "init-all"
33+
SMBD = "smbd"
34+
WINBINDD = "winbindd"
35+
CTDBD = "ctdbd"
36+
TARGETS = [SMBD, WINBINDD, CTDBD]
37+
38+
39+
class WaitForCTDBCondition:
40+
def met(self, ctx: Context) -> bool:
41+
target = getattr(ctx.cli, "target", None)
42+
if target == CTDBD:
43+
raise Fail(f"Can not start and wait for {CTDBD}")
44+
_logger.debug("Condition required: ctdb pnn available")
45+
import sambacc.ctdb
46+
47+
pnn = sambacc.ctdb.current_pnn()
48+
ok = pnn is not None
49+
_logger.debug(
50+
"Condition %s: ctdb pnn available: %s",
51+
"met" if ok else "not met",
52+
pnn,
53+
)
54+
return ok
55+
56+
57+
_wait_for_conditions = {"ctdb": WaitForCTDBCondition}
2858

2959

3060
def _run_container_args(parser):
@@ -47,6 +77,17 @@ def _run_container_args(parser):
4777
" The special 'init-all' name will perform all known setup steps."
4878
),
4979
)
80+
_wait_for_choices = _wait_for_conditions.keys()
81+
parser.add_argument(
82+
"--wait-for",
83+
action="append",
84+
choices=_wait_for_choices,
85+
help=(
86+
"Specify a condition to wait for prior to starting the server"
87+
" process. Available conditions: `ctdb` - wait for ctdb"
88+
" to run and provide a pnn."
89+
),
90+
)
5091
parser.add_argument(
5192
"--insecure-auto-join",
5293
action="store_true",
@@ -57,7 +98,7 @@ def _run_container_args(parser):
5798
)
5899
parser.add_argument(
59100
"target",
60-
choices=["smbd", "winbindd", "ctdbd"],
101+
choices=TARGETS,
61102
help="Which process to run",
62103
)
63104

@@ -67,6 +108,12 @@ def run_container(ctx: Context) -> None:
67108
"""Run a specified server process."""
68109
if ctx.cli.no_init and ctx.cli.setup:
69110
raise Fail("can not specify both --no-init and --setup")
111+
112+
if ctx.cli.wait_for:
113+
conditions = [_wait_for_conditions[n]() for n in ctx.cli.wait_for]
114+
while not all(c.met(ctx) for c in conditions):
115+
time.sleep(1)
116+
70117
# running servers expect to make use of ctdb whenever it is configured
71118
ctx.expects_ctdb = True
72119
if not ctx.cli.no_init and not ctx.cli.setup:

0 commit comments

Comments
 (0)