I would like to define a workflow to configure the thin-edge with the following requirements::
Case 1, called initially with c8yUrl:
- set the c8y.url and connect
- restart the mapper
Case 2, called consecutively, no c8yUrl:
- restart the mapper, e.g. mapper has to be reloaded since the device certificates have changed
To this end I defined the following workflow.
But it get stuck in state [configure] and never reaches successful.
How do I have to change the workflow that it reaches waiting_for_tedge_connect?
operation = "config_tedge"
[init]
action = "proceed"
on_success = "configure"
[configure]
script = "sh -c '[ -n ${.payload.c8yUrl} ]' && tedge config set c8y.url ${.payload.c8yUrl} && tedge connect c8y'"
on_exec = "waiting_for_tedge_connect"
[waiting_for_tedge_connect]
action = "await-operation-completion"
timeout_second = 60
on_timeout = "timeout_tedge_connect"
on_success = "restart_mapper"
on_error = { status = "failed", reason = "fail to update tedge config & tedge connect"}
[restart_mapper]
script = "tedgectl restart tedge-mapper"
on_success = "successful"
on_error = "failed"
[timeout_tedge_connect]
action = "proceed"
on_success = "failed"
[successful]
action = "cleanup"
[failed]
action = "cleanup"
The workflow doesn’t have to be that complicated.
Just some pointers with some of the issues from your workflow:
await-operation-completion
should only be used when you’ve called another workflow via the operation
property - see docs
on_exec
is used for background execution, e.g. when background_script
is used - see docs
- It is best practice to use the
[executing]
state (so that the user has clear indication when the workflow is starting to execute)
I’ve rewritten your workflow by just using the script
property (as you don’t need anything fancy here like background scripts).
- Use
check
to run the conditional logic in one place, which just checks if the user provided a c8yUrl
or not, and then decides which state should be executed next (without executing anything itself).
- Use
sudo tedge reconnect c8y
over tedgectl
…as the mapper will restart the appropriate services using the init system abstraction…Though you might need to add tedge
to sudoers list of allowed commands
- Split each action into different states. It is easier to read and work out where something failed.
operation = "config_tedge"
on_failure = "failed"
[init]
action = "proceed"
on_success = "executing"
[executing]
action = "proceed"
on_success = "check"
[check]
script = "sh -c '[ -n ${.payload.c8yUrl} ]'"
on_success = { status = "configure", reason = "configure url"}
on_error = { status = "successful", reason = "c8yUrl is not provided, so nothing to do"}
# Alternatively, you could fail the operation if you the c8yUrl is required
# on_exit._ = { status = "failed", reason = "c8yUrl was not provided. c8yUrl is a required argument"}
[configure]
script = "tedge config set c8y.url ${.payload.c8yUrl}"
on_success = "reconnect"
[reconnect]
script = "sudo tedge reconnect c8y"
on_success = "successful"
[successful]
action = "cleanup"
[failed]
action = "cleanup"
Sorry I didn’t read the full requirements…but a lot of the above comments still stand:
But this is an amended workflow which conditionally runs tedge config set c8y.url
if the user provides the c8yUrl
in the command’s payload, if not then it only restarts the mapper (it does not configure it).
operation = "config_tedge"
on_failure = "failed"
[init]
action = "proceed"
on_success = "executing"
[executing]
action = "proceed"
on_success = "check"
[check]
script = "sh -c '[ -n ${.payload.c8yUrl} ]'"
on_success = { status = "configure", reason = "configure url"}
on_error = { status = "restart_mapper", reason = "Just restart the mapper"}
[configure]
script = "tedge config set c8y.url ${.payload.c8yUrl}"
on_success = "restart_mapper"
[restart_mapper]
script = "sudo tedgectl restart tedge-mapper-c8y"
on_success = "successful"
[successful]
action = "cleanup"
[failed]
action = "cleanup"