r-lib / processx

Execute and Control Subprocesses from R
https://processx.r-lib.org/
Other
232 stars 43 forks source link

Running docker container #348

Closed latot closed 1 year ago

latot commented 1 year ago

Hi, I'm trying to run a temporary container from this lib, the idea is can set it up, work, and then close the process, docker will clean the files:

This will setup temporary Postgres Database with Postgis support (spatial data):

postgres <- processx::process$new(
    "docker",
    c(
        "run",
        "--rm",
        "-p", "5433:5432",
        "-e", "POSTGRES_USER=user",
        "-e", "POSTGRES_PASSWORD=password",
        "-e", "POSTGRES_DB=db",
        "postgis/postgis",
        "-c", "max_worker_processes=8",
        "-c", "max_parallel_workers=7",
        "-c", "max_parallel_workers_per_gather=7",
        "-c", "max_parallel_maintenance_workers=7"
    ),
    stdout = "|", stderr = "|"
)

Well, this is weird, because, first, I don't have any logs here, second, what I got is this:

> postgres
PROCESS 'docker', running, pid 27057.
#wait a few seconds
> postgres
PROCESS 'docker', finished.

So, for some reason it just finished.... D:

I tryied to use read_output_lines() but nothing.

Thx!

gaborcsardi commented 1 year ago

I cannot reproduce this, for me the container is running happily. (I only had to add --platform=linux/amd64 on arm Linux.)

What do

postgres$get_exit_status()
postgres$read_error()

say?

latot commented 1 year ago

Hi, I try put the param on docker, sadly, does not works, I should had provided more info.

I'm using Gentoo 64 (Linux)

> postgres <- processx::process$new(
    "docker",
    c(
        "run",
        "--rm",
        "-p", "5433:5432",
        "-e", "POSTGRES_USER=user",
        "-e", "POSTGRES_PASSWORD=password",
        "-e", "POSTGRES_DB=db",
        "postgis/postgis",
        "-c", "max_worker_processes=8",
        "-c", "max_parallel_workers=7",
        "-c", "max_parallel_workers_per_gather=7",
        "-c", "max_parallel_maintenance_workers=7", "--platform=linux/amd64"
    ))
> postgres
PROCESS 'docker', running, pid 94310.
> postgres
PROCESS 'docker', running, pid 94310.
> postgres
PROCESS 'docker', running, pid 94310.
> postgres
PROCESS 'docker', finished.
> postgres
PROCESS 'docker', finished.
> postgres$get_exit_status()
[1] 125
> postgres$read_error()
Error in `process_get_error_connection(self, private)`:
! stderr is not a pipe.
Type .Last.error to see the more details.
> .Last.error
<rlib_error_3_0/rlib_error/error>
Error in `process_get_error_connection(self, private)`:
! stderr is not a pipe.
---
Backtrace:
1. postgres$read_error()
2. processx:::process_read_error(self, private, n)
3. processx:::process_get_error_connection(self, private)
4. processx:::throw(new_error("stderr is not a pipe."))
gaborcsardi commented 1 year ago

You still need to use stdout = "|", stderr = "|" to be able to read the standard output and error.

latot commented 1 year ago

Well, there is a weird things:

Instead kill, interrupt does the trick :)

Thx!

gaborcsardi commented 1 year ago

You can use $signal(15) to send a SIGTERM, that is better than SIGINT and SIGKILL.

I don't get why we need platform from R, in the terminal all works fine without that param.

You might not, I needed it, because I am on an arm machine, and this container seems to be amd64 only.

latot commented 1 year ago

Hi, seems signal 15 does not close it, for now only works interrupt.