osrm_stop: Stop an OSRM Server

View source: R/osrm_stop_server.R

osrm_stopR Documentation

Stop an OSRM Server

Description

[Stable]

Terminates an osrm-routed process launched by osrm_start() or osrm_start_server(). Can also stop external servers by PID or ID.

Usage

osrm_stop(
  server = NULL,
  id = NULL,
  port = NULL,
  pid = NULL,
  wait = 1000L,
  quiet = FALSE
)

Arguments

server

Optional OSRM job process (an osrm_server object inheriting from processx::process) returned by osrm_start_server().

id

Optional character id from osrm_servers().

port

Optional integer TCP port.

pid

Optional integer process id.

wait

Integer milliseconds to wait for clean shutdown (default 1000).

quiet

Logical; suppress messages (default FALSE).

Details

This function provides a flexible way to stop a running OSRM process. If no arguments are specified, it defaults to stopping the most recently started server that is still alive in the current session.

You can also stop a specific server by providing:

  • The OSRM job process (a processx::process object) returned by osrm_start() or osrm_start_server().

  • The server's id, port, or pid (use osrm_servers() to find these).

Advanced Use: You can stop an external osrm-routed process (one not started by the current R session) by passing its PID, or by finding it via osrm_servers(include_all = TRUE) and passing its id or port. This requires permission to signal the process.

Value

A list with fields id, pid, port, stopped (logical).

See Also

osrm_start(), osrm_servers(), osrm_stop_all()

Examples


if (identical(Sys.getenv("OSRM_EXAMPLES"), "true")) {
  install_dir <- osrm_install(
    version = "latest",
    path_action = "session",
    quiet = TRUE
  )

  # copy example OSM PBF into a temporary workspace to avoid polluting pkg data
  pbf_path <- system.file("extdata/cur.osm.pbf", package = "osrm.backend")
  osrm_dir <- file.path(tempdir(), paste0("osrm-", Sys.getpid()))
  dir.create(osrm_dir, recursive = TRUE)
  tmp_pbf <- file.path(osrm_dir, "cur.osm.pbf")
  file.copy(from = pbf_path, to = tmp_pbf, overwrite = TRUE)
  graph <- osrm_prepare_graph(tmp_pbf, overwrite = TRUE, threads = 1L)

  srv <- osrm_start_server(graph$osrm_job_artifact, port = 6000, threads = 1L)

  # Stop by passing the process object
  osrm_stop(srv)

  # Or stop by port after the process is registered
  osrm_stop(port = 6000)

  osrm_uninstall(
    dest_dir = install_dir,
    clear_path = TRUE,
    force = TRUE,
    quiet = TRUE
  )
  unlink(osrm_dir, recursive = TRUE)
}

## Not run: 
  # Advanced: Stop an external server by PID
  # 1. Find the PID of an external server
  srvs <- osrm_servers(include_all = TRUE)
  # 2. Stop it by PID
  if (nrow(srvs) > 0) {
    osrm_stop(pid = srvs$pid[1])
  }
  
  # Or stop by its external ID (e.g., "sys-12345")
  osrm_stop(id = "sys-12345")

## End(Not run)


osrm.backend documentation built on April 26, 2026, 9:06 a.m.