View source: R/osrm_start_server.R
| osrm_start_server | R Documentation |
osrm-routedLaunches an osrm-routed process pointing at a localized OSRM graph (either
.osrm.mldgr for MLD or .osrm.hsgr for CH/CoreCH).
osrm_start_server(
osrm_path,
version = FALSE,
help = FALSE,
verbosity = c("INFO", "ERROR", "WARNING", "NONE", "DEBUG"),
trial = FALSE,
ip = "0.0.0.0",
port = 5001L,
threads = 8L,
shared_memory = FALSE,
memory_file = NULL,
mmap = FALSE,
dataset_name = NULL,
algorithm = NULL,
max_viaroute_size = 500L,
max_trip_size = 100L,
max_table_size = 100L,
max_matching_size = 100L,
max_nearest_size = 100L,
max_alternatives = 3L,
max_matching_radius = -1L,
quiet = FALSE,
verbose = FALSE,
echo_cmd = FALSE,
input_osm = NULL
)
osrm_path |
Character(1). Path to the |
version |
Logical; if |
help |
Logical; if |
verbosity |
Character; one of |
trial |
Logical or integer; if |
ip |
Character; IP address to bind (default: |
port |
Integer; TCP port to listen on (default: |
threads |
Integer; number of worker threads (default: |
shared_memory |
Logical; load graph from shared memory (default: |
memory_file |
Character or NULL; DEPRECATED (behaves like |
mmap |
Logical; memory-map data files (default: |
dataset_name |
Character or NULL; name of shared memory dataset |
algorithm |
Character or NULL; one of |
max_viaroute_size |
Integer (default: |
max_trip_size |
Integer (default: |
max_table_size |
Integer (default: |
max_matching_size |
Integer (default: |
max_nearest_size |
Integer (default: |
max_alternatives |
Integer (default: |
max_matching_radius |
Integer; use |
quiet |
Logical; when |
verbose |
Logical; when |
echo_cmd |
Logical; echo command line to console before launch (default: |
input_osm |
Character or NULL; path to the original OSM input file (for tracking purposes).
This parameter is typically used internally by |
The server's standard output and error streams are handled via temporary files by default to prevent deadlocks in R's single-threaded environment. This ensures reliable operation while preserving logs for debugging startup failures.
To customize logging behavior, you can use the following approaches:
Default (Temp File): Logs are written to a temporary file. This prevents deadlocks while keeping logs available for debugging.
Verbose Mode: Set verbose = TRUE to display logs directly in the
R console. Note: This can cause deadlocks in tight loops if R is busy.
Custom Log File: Set the osrm.server.log_file option to redirect
output to a specific file:
options(osrm.server.log_file = "path/to/osrm.log")
Note: List specifications (e.g., `list(stdout = "...", stderr = "...")`) are deprecated and will fall back to the default temporary file behavior.
You can override the osrm-routed executable via
options(osrm.routed.exec = "/full/path/to/osrm-routed").
An OSRM job process (an osrm_server object inheriting from
processx::process) for the running server (also registered internally).
if (identical(Sys.getenv("OSRM_EXAMPLES"), "true")) {
install_dir <- osrm_install(
version = "latest",
path_action = "session",
quiet = TRUE
)
# Build a graph then launch an OSRM server on a custom port
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(
input_osm = tmp_pbf,
overwrite = TRUE,
threads = 1L,
algorithm = "mld"
)
server <- osrm_start_server(
osrm_path = graph$osrm_job_artifact,
port = 6000,
threads = 1L
)
# Later, stop the server again
osrm_stop(server)
osrm_uninstall(
dest_dir = install_dir,
clear_path = TRUE,
force = TRUE,
quiet = TRUE
)
unlink(osrm_dir, recursive = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.