binwiederhier / replbot

Slack/Discord bot for running interactive REPLs and shells from a chat.
Apache License 2.0
199 stars 8 forks source link

Failed to start tmux using Docker #35

Closed ghost closed 3 years ago

ghost commented 3 years ago

Using the latest Docker image, replbot seems to be unable to start tmux. Also using the latest config and script.d files. I haven't had much time to look into this yet and have not tested using replbot straight from Go or with a direct install, but figured I'd at least document it here. I am using the latest version of Docker and the host is Ubuntu 20.04.3. Let me know if I can provide any more info!

root@localhost:~# docker run --rm -it \
>   -v /etc/replbot:/etc/replbot \
>   -v /var/run/docker.sock:/var/run/docker.sock \
>   binwiederhier/replbot
Unable to find image 'binwiederhier/replbot:latest' locally
latest: Pulling from binwiederhier/replbot
ba3557a56b15: Pull complete 
94caa5d1da70: Pull complete 
a10a29983da5: Pull complete 
3d6ccddb7fa4: Pull complete 
ed1bef566495: Pull complete 
201a9d1142eb: Pull complete 
0806b78d1f4d: Pull complete 
2987e14e0ec7: Pull complete 
cf93861db271: Pull complete 
Digest: sha256:cc83a8a0613674a70b25d7bf7a23a536b2183a0eed47845f54456696f88f388e
Status: Downloaded newer image for binwiederhier/replbot:latest
2021/09/22 17:52:10 Discord connected as user REPLbot
2021/09/22 17:52:14 [773039894888579092_890294434044993566] Starting session, requested by axite
2021/09/22 17:52:14 [773039894888579092_890294434044993566] Started REPL session
2021/09/22 17:52:14 [773039894888579092_890294434044993566] Failed to start tmux: exit status 1
2021/09/22 17:52:14 [773039894888579092_890294434044993566] Closed REPL session
2021/09/22 17:52:14 [773039894888579092_890294434044993566] Session exited with error: exit status 1
binwiederhier commented 3 years ago

I'm looking now

binwiederhier commented 3 years ago

So I apologize for the logs being as bad as they are, and I think there is a lot of room for improvement. I think I may have to add some debug logging too, since this is clearly not helpful.

I tried the latest docker image and it "works for me", ... however I was able to produce the same output by making the actual script that you're running fail with exit 1, e.g. /etc/replbot/script.d/failme

#!/bin/sh
exit 1

What you could also try a different --entrypoint /bin/sh, and then run the script manually:

# On the laptop:
pheckel@laptop$ docker run --rm -it --entrypoint /bin/sh \
  -v /etc/replbot:/etc/replbot \
  -v /var/run/docker.sock:/var/run/docker.sock \
  binwiederhier/replbot:v0.5.0

# We're now in the REPLbot image
/ # cd /etc/replbot/script.d/
/etc/replbot/script.d # ./ubuntu run abc

# We're now in the ubuntu image
root@7c57aa73e5b9:/# ls

If that works then it's got to be something with the tmux calls

ghost commented 3 years ago

I think I found the issue, oops on my part. Looks like all of the scripts are in DOS format 🤦🏼‍♂️

root@localhost:/etc/replbot/script.d# ./ubuntu run abc
-bash: ./ubuntu: /bin/sh^M: bad interpreter: No such file or directory

Converted them to Unix..

dos2unix: converting file docker-kill to Unix format...
root@localhost:/etc/replbot/script.d/helpers# dos2unix docker-run 
dos2unix: converting file docker-run to Unix format...
root@localhost:/etc/replbot/script.d# dos2unix ubuntu 
dos2unix: converting file ubuntu to Unix format...

And like magic..

>   -v /etc/replbot:/etc/replbot \
>   -v /var/run/docker.sock:/var/run/docker.sock \
>   binwiederhier/replbot
2021/09/22 20:27:00 Discord connected as user REPLbot/880575037789323355
2021/09/22 20:27:06 [702977813409693766_890333410814480486] Starting session, requested by 360597009301897236
2021/09/22 20:27:06 [702977813409693766_890333410814480486] Started REPL session

Sorry for the time waste! I think it was due to me copying the files from my local replbot repo which was last edited in VS code, but I'll have to dig into that more. Thank you for looking into it anyways 😅

binwiederhier commented 3 years ago

So the scripts we ship with are fine?

Also: not a waste, since it just means I need better logging.

ghost commented 3 years ago

Yep! I noticed the bash interpreter issue which was due to all the scripts being in DOS format (pulled from my Windows desktop). It was seeing ^M as an illegal character. I find it weird they got converted automatically but I'll have to dig into that more. After cloning the repo directly to Ubuntu and copying from there, it all works fine.