serviceDescriptor function

  1. @visibleForTesting
ServiceDescriptor serviceDescriptor(
  1. String role,
  2. ArgResults args
)

Builds the descriptor that installs this omnyserver executable to run omnyserver <role> start … with the flags captured from args.

Implementation

@visibleForTesting
svc.ServiceDescriptor serviceDescriptor(String role, ArgResults args) {
  rejectForeignOptions(role, args);
  if (role == 'hub') {
    validateHubTls(args);
  } else {
    validateNodeStartArgs(args);
  }
  final systemScope = args['system'] as bool;
  final scope = systemScope ? svc.ServiceScope.system : svc.ServiceScope.user;

  // Both roles: pin OMNYSERVER_HOME. `OmnyServerHome.resolve()` falls back to
  // $HOME and then to the system temp dir, and a system service has no
  // meaningful $HOME — without this a node would keep its machine-UID file in
  // /tmp and re-register as a brand-new node after every reboot.
  final root = resolveDataDir(args, systemScope: systemScope);
  final env = <String, String>{'OMNYSERVER_HOME': ?root};

  return svc.ServiceDescriptor.forCurrentExecutable(
    packageName: servicePackage,
    serviceName: role,
    arguments: serviceStartArgs(role, args),
    environment: env,
    scope: scope,
    restart: svc.RestartPolicy.always,
  );
}