Skip to content

Commit

Permalink
Fixes for windoze
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Jul 20, 2013
1 parent d2d35ca commit 4e2b1d7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 deletions.
12 changes: 5 additions & 7 deletions R/inlib.R
@@ -1,13 +1,11 @@
inlib <- function(lib, expr, addbaselib=TRUE, addsitelib=TRUE){
inlib <- function(lib, expr, add=TRUE){
oldlib <- .libPaths();
on.exit(
setlib(oldlib)
);
if(isTRUE(addsitelib)){
lib <- c(lib, base:::.Library.site);
} else if(isTRUE(addbaselib)){
lib <- c(lib, base:::.Library);
}
)
if(isTRUE(add)){
lib <- c(lib, .libPaths());
}
lib <- unique(normalizePath(lib, mustWork=FALSE));
lib <- Filter(function(x){
isTRUE(file.info(x)$isdir)
Expand Down
53 changes: 30 additions & 23 deletions R/onAttach.R
@@ -1,42 +1,49 @@
.onAttach <- function(path, package){
#httpuv should not be started in rapache or during R CMD INSTALL --test-load
if(interactive() && !("rapache" %in% search()) && !("--slave" %in% commandArgs())) {
#Cloud specific stuff
if("rapache" %in% search()){

#remove custom system lib
.libPaths(c(.Library.site, .Library));

#Check for RAppArmor when using Apache
if(!isTRUE(getOption("hasrapparmor"))){
warning("SECURITY WARNING: OpenCPU is running without RAppArmor.");
}
} else {
#Dont run in rscript
if(!interactive() || ("--slave" %in% commandArgs())){
return();
}

#loaded from within R
message("Initiating OpenCPU server...")

#start rhttpd only in rstudio server
if(nchar(Sys.getenv("RSTUDIO_HTTP_REFERER"))){
rhttpd$init();
}

#Start HTTPUV
httpuv$start();
Sys.sleep(1);
httpuv$browse();

#NOTE: browse() commands are for debugging only
#in practice, apps should be calling browse()
}

#Check for RAppArmor when using Apache
if("rapache" %in% search() && !isTRUE(getOption("hasrapparmor"))){
warning("SECURITY WARNING: OpenCPU is running without RAppArmor.");
}
#Make sure httpuv stops when exiting R.
if(!exists(".Last", globalenv())){
exitfun <- function(){
try({
ocpu:::httpuv$stop();
rm(".Last", envir=globalenv());
}, silent=TRUE);
}

#Make sure httpuv stops when exiting R.
if(!exists(".Last", globalenv())){
exitfun <- function(){
try({
ocpu:::httpuv$stop();
rm(".Last", envir=globalenv());
}, silent=TRUE);
}

environment(exitfun) <- globalenv();
assign(".Last", exitfun, globalenv());
environment(exitfun) <- globalenv();
assign(".Last", exitfun, globalenv());
}

message("OpenCPU server ready.");
}

message("OpenCPU server ready.");
}

.onDetach <- function(libpath){
Expand Down
10 changes: 4 additions & 6 deletions R/onLoad.R
Expand Up @@ -35,13 +35,11 @@ packagename = "";

if(.Platform$OS.type != "windows"){
Sys.setlocale(category='LC_ALL', 'en_US.UTF-8');
}

#add non-system opencpu libraries
if(length(config("libpaths")) > 0){
.libPaths(unlist(config("libpaths")));
} else {
.libPaths(.Library.site);
#add non-system opencpu libraries
if(length(config("libpaths")) > 0){
.libPaths(unlist(config("libpaths")));
}
}

#preload libraries
Expand Down

0 comments on commit 4e2b1d7

Please sign in to comment.