hashicorp / nomad

Nomad is an easy-to-use, flexible, and performant workload orchestrator that can deploy a mix of microservice, batch, containerized, and non-containerized applications. Nomad is easy to operate and scale and has native Consul and Vault integrations.
https://www.nomadproject.io/
Other
14.76k stars 1.94k forks source link

[Improvement] Configurable working directory for exec/raw_exec #2224

Open dradtke opened 7 years ago

dradtke commented 7 years ago

The exec and raw_exec drivers should be able to configure the working directory just like the docker driver can.

dradtke commented 7 years ago

I actually just realized that there may be some security implications with this change, but it could be minimized by disallowing traversal outside of the specified directory. It also wouldn't play the best with the environment that's set up for a task, but that may or may not be very important.

ashald commented 7 years ago

IIUC, isn't it's something that can be achieved as

config {
        command = "/bin/bash"
        args    = [
                "-c",
                "cd /my/work/dir && exec $@",
                "my-executable"
        ]
      }

?

kaskavalci commented 7 years ago

This worked for me:

"Config": {
    "args": [
        "-c",
        "cd /my/work/dir && my-executable arg1 arg2 ..."
    ],
    "command": "/bin/sh"
}
srene2795 commented 6 years ago

How do we propagate kill signal to the application when we execute binary like this ?

"Config": { "args": [ "-c", "cd /my/work/dir && my-executable arg1 arg2 ..." ], "command": "/bin/sh" }

dradtke commented 6 years ago

I think you can do that by prefixing your executable with exec, e.g.

"Config": {
  "args": ["-c", "cd /my/work/dir && exec my-executable arg1 arg2 ..."],
  "command": "/bin/sh"
}

The idea is to have the shell process actually replace itself with your executable, rather than create a separate subprocess.

nicholastcs commented 4 years ago

Is this going to be enhanced in the future? Because certain legacy windows application requires to be run with executing directory = .exe directory.

I know it can be workaround with command = "powershell", then traverse directory with args = ["cd ...", ... ].

pcbl commented 4 years ago

Hi @tgross , Me again. :-) Out of curiosity, do you know if there are any plan regarding this possibility of setting the Working Directory of the raw_exec driver?

We have a case where we need to set(it is about a legacy application which demands to work on a specific dir)... So far we do alternatives libe cd "path" && run , but would be very nice if we would be abble to set it from the driver.

BR Pedro

tgross commented 4 years ago

We don't have it on our "coming soon" roadmap. So beyond that I couldn't really say when to expect this sort of thing. We'd definitely be open to a PR for it though!

pcbl commented 4 years ago

All clear. thanks for the heads up!

picatz commented 3 years ago

Just ran into this problem today. Would love to have this feature.

elghazal-a commented 3 years ago

I have the same issue when running a nodejs app, it would be great to have a working directory setting

tgross commented 1 month ago

Internal ref: https://hashicorp.atlassian.net/browse/NET-10162