AsherGlick / ResourceCalculator

A Video Game Resource Calculator
https://resourcecalculator.com
GNU General Public License v3.0
56 stars 30 forks source link

Running `./run.sh` creates containers but doesn't terminate script. `ctrl-c` quits script but stops containers? #84

Closed ASchneider-GitHub closed 1 year ago

ASchneider-GitHub commented 1 year ago

I cloned to repo to an Ubuntu 20.04 host with Docker and docker-compose installed, and everything gets set up correctly when running ./run as root. After running the script I get the output

root@docker-host:/home/<user>/ResourceCalculator# ./run.sh
./run.sh: line 3: UID: readonly variable
Creating resourcecalculator_build_1 ... done
Creating resourcecalculator_web_1   ... done
Attaching to resourcecalculator_web_1, resourcecalculator_build_1
build_1  | 0 :
web_1    | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
web_1    | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
web_1    | [Thu Aug 04 06:54:26.290970 2022] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.54 (Debian) PHP/8.1.8 configured -- resuming normal operations
web_1    | [Thu Aug 04 06:54:26.301336 2022] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
build_1  |
build_1  | up to date, audited 126 packages in 786ms
build_1  |
build_1  | 3 packages are looking for funding
build_1  |   run `npm fund` for details
build_1  |
build_1  | found 0 vulnerabilities
build_1  |
build_1  | [notice] A new release of pip available: 22.2.1 -> 22.2.2
build_1  | [notice] To update, run: pip install --upgrade pip
build_1  | ARGS:
resourcecalculator_build_1 exited with code 0

but then the script doesn't terminate. Instead it seemingly hangs until it's manually stopped with ctrl-c. When terminating the script that way, the Docker contains are both stopped and the web instance goes down. The only way to get out of the script without stopping it is to close out of my SSH session entirely and log back in.

Is there a way to terminate the script without closing out the containers?

AsherGlick commented 1 year ago

You want a way to only exit the build script but leave the webserver running? This should happen normally if you do not include the --watch flag and looks like it is happening here on that last line of your log with

resourcecalculator_build_1 exited with code 0

Meaning that now only the webserver is still running at this point which you should be able to verify with docker ps. Hitting ctrl-c after build has exited will kill all the remaining containers which is would just be the webserver.

If what you are hoping to do is have the webserver (and maybe also the build script) run in the background you can employ a couple of different options. One is to modify the run.sh script's last line to add the detach flag.

  # Run docker compose
- docker-compose up
+ docker-compose up -d

this will caused docker-compose to spin up its containers in detached mode and return the terminal to you immediately. This means that you will not have easy access to the output logs for either the webserver or the build script.

The other is to employ a terminal multiplexer like screen or tmux and run run.sh in one of their sessions, then exit out of their sessions back to your original ssh prompt.

If I am not understanding your usecase can you explain what you are hoping to accomplish at a higher level?

ASchneider-GitHub commented 1 year ago

If what you are hoping to do is have the webserver (and maybe also the build script) run in the background you can employ a couple of different options. One is to modify the run.sh script's last line to add the detach flag.

  # Run docker compose
- docker-compose up
+ docker-compose up -d

this will caused docker-compose to spin up its containers in detached mode and return the terminal to you immediately. This means that you will not have easy access to the output logs for either the webserver or the build script. I am not understanding your usecase can you explain what you are hoping to accomplish at a higher level?

This might actually be what I'm looking for. I didn't do a good job of explaining it, which is my bad. I have an Ubuntu server running Docker with multiple containers that I manage through the CLI. I cloned the ResourceCalculator repo to Docker host, cdd into the grabbed folder, and ran sudo ./run.sh to launch the resource. The script goes through what I assume is the normal deployment process with Docker Compose, and then returns the message

resourcecalculator_build_1 exited with code 0

Instead of then returning me to the CLI so I can continue doing work on other containers, it "locks" you into the script. If you back out with ctrl-c, the script terminates but the WebUI container is brought down as well. I was looking for a way to back out of the script without shutting down the container. So far the only solution I was found was to use an SSH session on Windows to start the container, and then closing the actual WSL application to cut the connection without terminating the script. After that I can SSH back in and the container will be left running. Not the cleanest approach, so I'll give your method a shot with the detached mode

AsherGlick commented 1 year ago

Glad to have been able to help. If this solved your question you may close this issue.