Skip to content

Commit f01b8d1

Browse files
committed
Refactored startGobbler to allow extra arguments to be passed to the binary.
We also allow customization of the administrator list.
1 parent 1945ef1 commit f01b8d1

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

R/startGobbler.R

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#' @param wait Integer specifying the number of seconds to wait for service initialization.
1313
#' @param overwrite Logical scalar indicating whether to redownload the Gobbler binary.
1414
#' @param version String containing the desired version of the Gobbler binary.
15+
#' @param admin Character vector of user names of the Gobbler administrators.
16+
#' If \code{NULL}, this defaults to the current user.
17+
#' @param extra.args Character vector of extra arguments to pass to the Gobbler binary.
18+
#' If \code{NULL}, no extra arguments are added.
1519
#'
1620
#' @return For \code{startGobbler}, a list containing:
1721
#' \itemize{
@@ -36,7 +40,7 @@
3640
#'
3741
#' @export
3842
#' @importFrom utils download.file
39-
startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, wait = 1, version = "0.5.0", overwrite = FALSE) {
43+
startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, wait = 1, version = "0.5.0", overwrite = FALSE, admin = NULL, extra.args = NULL) {
4044
if (!is.null(running$active)) {
4145
return(list(new=FALSE, staging=running$staging, registry=running$registry, port=running$port, url=assemble_url(running$port)))
4246
}
@@ -49,7 +53,7 @@ startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, w
4953
cache <- tools::R_user_dir("gobbler", "data")
5054

5155
sinfo <- Sys.info()
52-
sysname <- sinfo["sysname"]
56+
sysname <- sinfo[["sysname"]]
5357
if (sysname == "Darwin") {
5458
os <- "darwin"
5559
} else if (sysname == "Linux") {
@@ -58,7 +62,7 @@ startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, w
5862
stop("unsupported operating system '", sysname, "'")
5963
}
6064

61-
sysmachine <- sinfo["machine"]
65+
sysmachine <- sinfo[["machine"]]
6266
if (sysmachine == "arm64") {
6367
arch <- "arm64"
6468
} else if (sysmachine == "x86_64") {
@@ -91,10 +95,18 @@ startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, w
9195
if (is.null(port)) {
9296
port <- choose_port()
9397
}
98+
if (is.null(admin)) {
99+
admin <- sinfo[["user"]]
100+
}
94101

95-
self <- sinfo["user"]
102+
args <- c(shQuote(exe), "-staging", shQuote(staging), "-registry", shQuote(registry), "-port", shQuote(port))
103+
if (length(admin)) {
104+
args <- c(args, "-admin", shQuote(paste(admin, collapse=",")))
105+
}
106+
args <- c(args, extra.args)
107+
96108
script <- system.file("scripts", "deploy.sh", package="gobbler", mustWork=TRUE)
97-
pid <- system2(script, c(shQuote(exe), shQuote(staging), shQuote(registry), shQuote(self), shQuote(port)), stdout=TRUE)
109+
pid <- system2(script, args, stdout=TRUE)
98110
Sys.sleep(wait)
99111

100112
process <- new.env()

inst/scripts/deploy.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# We shovel this into a shell script as system(2) doesn't like multiple
44
# statements, especially if one of them is backgrounded. We need to do
55
# multiple statements so that we can run `$!` to get the PID.
6-
"$1" -staging "$2" -registry "$3" -admin "$4" -port "$5" > /dev/null &
6+
"$@" > /dev/null &
77
PID=$!
8-
9-
sleep 1 # Give it a second to set up before it's considered 'ready'.
108
echo $PID

man/startGobbler.Rd

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)