hotel icon indicating copy to clipboard operation
hotel copied to clipboard

Option for setting command for what happens when turning process off

Open patrickoliveras opened this issue 7 years ago • 8 comments

I work a lot in PHP and Apache and Nginx run once on startup but don't hold the process in the terminal.

Right now I have something along the lines of:

hotel add 'nginx -c /my/server/config.conf; open -a "Google Chrome" "localhost:8081"; tail -f "my.log"' --name 'myserver'

For servers like Rails and Node there isn't much of a problem, since closing them on hotel just ends the command, but it's not so simple for PHP servers other than PHP-CLI.

I was trying to find a way to define what happens when you turn off the option in the hotel page, since right now it only closes the 'tail' command part. What I'd really want is to be able to define a command for that moment i.e. 'nginx -s stop'.

I expect something along these lines could really expand the use cases for hotel.

Cheers! 🖐

patrickoliveras avatar Mar 23 '17 02:03 patrickoliveras

I love this idea for use with docker. Starting containers is great, but hotel needs to issue another command to stop the container.

hotel add --name guessit -p 5000 'docker run --rm -p 127.0.0.1:$PORT:5000 --name guessit guessit/guessit-rest'

switch on works great, but switch off doesn't kill the container. must manually run:

docker stop guessit

it would be awesome if typicode could issue that command on switch off

jpuck avatar Apr 06 '17 03:04 jpuck

If anyone has an idea how one would go about doing this, I might have some time to put together a pull request. 🤞

patrickoliveras avatar Nov 08 '17 18:11 patrickoliveras

How about an interface like this?

# in the `guessit` directory
hotel add --docker --expose 5000 guessit/guessit-rest -- --rm
# adds `.../hotel/bin/docker.js --expose 5000 guessit/guessit-rest -- --rm` which:
# => runs `docker run -p 127.0.0.1:$PORT:5000 --name guessit guessit/guessit-rest --rm`
#                               --expose ^^^^   $PWD ^^^^^^^     stuff after `--` ^^^^
# => on SIGTERM, runs `docker stop guessit` and exits
#                             $PWD ^^^^^^^

j-f1 avatar Nov 16 '17 15:11 j-f1

@j-f1 if you're implying a special flag for docker in hotel which wraps docker-specific options, then I would say no.

Much more useful would be an option to pass a generic command to call on switch off. That way other applications besides docker that need a callback to fire on shutdown could use it.

jpuck avatar Nov 16 '17 17:11 jpuck

Alternatively, run Docker as interactive (-it) and it will no longer auto daemonize: docker run -it --rm -p 127.0.0.1:$PORT:5000 --name guessit guessit/guessit-rest

fengb avatar Nov 16 '17 19:11 fengb

@patrickoliveras and @jpuck Does the comment above fix this issue for you?

j-f1 avatar Nov 18 '17 18:11 j-f1

@j-f1 that looks like it would work for docker, but the original issue is in regards to nginx. I think the feature request is for an optional callback to fire a custom command on shutdown. This would allow a generic solution for any scenario.

jpuck avatar Nov 18 '17 19:11 jpuck

A stop command will also help with tools like overmind. As it is now, if you start a rails server with it, it does not stop.

jonian avatar Dec 02 '18 22:12 jonian