View source: R/osrm_stop_server.R
| osrm_stop | R Documentation |
Terminates an osrm-routed process launched by osrm_start() or
osrm_start_server(). Can also stop external servers by PID or ID.
osrm_stop(
server = NULL,
id = NULL,
port = NULL,
pid = NULL,
wait = 1000L,
quiet = FALSE
)
server |
Optional OSRM job process (an |
id |
Optional character id from |
port |
Optional integer TCP port. |
pid |
Optional integer process id. |
wait |
Integer milliseconds to wait for clean shutdown (default |
quiet |
Logical; suppress messages (default |
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.
A list with fields id, pid, port, stopped (logical).
osrm_start(), osrm_servers(), osrm_stop_all()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.