Show Notes: The Agent is In - Episode 22 - Hackathon: Termux Services

Posted by Nick Anderson
February 23, 2023

Have a burning desire to run sshd or another service on your VR headset?

Cody, Craig and Nick do time-boxed live hackathon working on developing CFEngine services promise type support for Termux. Watch Nick and Craig race to implement basic services support before the timer buzzes.

Video

The video recording is available on YouTube:

At the end of every webinar, we stop the recording for a nice and relaxed, off-the-record chat with attendees. Join the next webinar to not miss this discussion.

Termux services policy

Here is the snippet of policy developed during the episode.

bundle agent __main__
{
  services:
      "sshd"
        service_policy => "stopped",
        service_method => termux_services;

}

bundle agent termux_services(service, policy)
# @brief Manage service state in Termux
# @param service The name of the service to manage, e.g. `sshd`
# @param policy The desired state of the service (`running`|`stopped`)
{
  classes:
      "service_running"
        expression => regcmp(
          "^run:.*",
          execresult("sv status ${service}", "useshell")
        );

      "service_stopped"
        expression => regcmp(
          "^down:.*",
          execresult("sv status ${service}", "useshell")
        );

      "policy_running"
        expression => strcmp("${policy}", "running");
      "policy_stopped"
        expression => strcmp("${policy}", "stopped");

  commands:
    service_stopped.policy_running::
      "sv up ${service}"
        contain => useshell;

    service_running.policy_stopped::
      "sv down ${service}"
        contain => useshell;
}

body service_method termux_services
{
  service_bundle => default:termux_services(
    ${this.promiser}, ${this.service_policy});
}

body contain useshell
{
  useshell => "useshell";
}

Note: Further work remains, notably “enabling” the service if it’s not yet been enabled and integrating it into the Masterfiles Policy Framework and the standard_services bundle.

Get in touch with us
to discuss how we can help!
Contact us
Sign up for
our newsletter
By signing up, you agree to your email address being stored and used to receive newsletters about CFEngine. We use tracking in our newsletter emails to improve our marketing content.