Example for running the nomad-skeleton-driver-plugin as a service

From the nomad-skeleton-driver-plugin I did a simple test by changing the job configuration from batch to service and putting the process to sleep for 10 seconds in order to simulate a running service.

job "example" {
  datacenters = ["dc1"]
  type        = "service"  # change from batch to service
  ...
func (d *HelloDriverPlugin) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drivers.DriverNetwork, error) {
...
execCmd := &executor.ExecCommand{
	Args:       []string{"-c", `sleep 10`},  // fake 10 seconds running service
  ...

The task runs and is rescheduled after completion, with exit code 0, as if the nomad client did not report the correct status.

I would like to have an example of how services should be executed and completed correctly and what is the programmatic difference with the batch implementation?

Thanks in advance.

Hey @aiqency :wave:

Nomad service type job is expected to remain running until explicitly stopped by an operator. Any exit, regardless of code, is considered “unexpected” and Nomad restarts the task—so the behavior you observed is expected.

Jobs that are expected to exit should be batch type. You can read more about the different job types in the Schedulers documentation.

Hopefully this points you in the right direction.

1 Like

Hopefully this points you in the right direction

It does :+1:. Thank you for these clarifications, much appreciated.