taylorthurlow/panda-motd

Service Status Component: ASCII ArgumentError

Closed this issue · 11 comments

Bug description

There is a string encoding bug when printing services and their status.
panda-motd had errors. Check '/var/log/panda-motd.error.log'.

/var/lib/gems/2.3.0/gems/panda-motd-0.0.7/lib/panda_motd/components/service_status.rb:41:in `delete': invalid byte sequence in US-ASCII (ArgumentError)
    from /var/lib/gems/2.3.0/gems/panda-motd-0.0.7/lib/panda_motd/components/service_status.rb:41:in `parse_services'
    from /var/lib/gems/2.3.0/gems/panda-motd-0.0.7/lib/panda_motd/components/service_status.rb:16:in `process'
    from /var/lib/gems/2.3.0/gems/panda-motd-0.0.7/lib/panda_motd/motd.rb:9:in `each'
    from /var/lib/gems/2.3.0/gems/panda-motd-0.0.7/lib/panda_motd/motd.rb:9:in `initialize'
    from /var/lib/gems/2.3.0/gems/panda-motd-0.0.7/lib/panda_motd.rb:9:in `new'
    from /var/lib/gems/2.3.0/gems/panda-motd-0.0.7/lib/panda_motd.rb:9:in `new_motd'
    from /var/lib/gems/2.3.0/gems/panda-motd-0.0.7/bin/panda-motd:5:in `<top (required)>'
    from /usr/local/bin/panda-motd:23:in `load'
    from /usr/local/bin/panda-motd:23:in `<main>'

Adding export LANG=en_US.UTF-8 to /etc/update-motd.d/00-panda-motd resolves the issue for now

Reproduction steps

  1. Follow the steps in the wiki to setup panda-motd
  2. SSH into the server after activating

Expected behavior

The configured MOTD would print

OS Information

  • OS: Ubuntu 16.04 LTS

Configuration File

https://gist.github.com/sroche0/7f131d8874aed54ea631059784b66b95

Interesting. Not exactly sure why it would be complaining. Do you mind posting the output of systemctl | grep '\.service'?

EDIT: Also, what is the value of $LANG if you don't override it in the MOTD script?

Here's the systemctl output https://gist.github.com/sroche0/a92d422e3ba096eef528312866df01fb

And LANG is the same by default, which is weird.

shawn@Citadel:~ > echo $LANG
en_US.UTF-8

Hmm, yeah that's odd. Your systemctl output looks more or less identical to mine - the non-ASCII circular characters caused an issue for me too, that's why I made it remove non-ASCII characters after running the command.

Can you double check your Ruby version for me? (ruby -v)

Also, do you mind running a Ruby console (irb) and running:

'● postgresql@9.3-main.service'.delete("^\u{0000}-\u{007F}")

Let me know if that throws an error. It should just return the string without the character.

@filalex77 His error log path contains panda-motd-0.0.7 so he's actually up to date it looks like.

@taylorthurlow Saw that too late, so deleted. Puzzled by this, too.

Ruby Version:

shawn@Citadel:~ > ruby -v
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]

And the string delete:

irb(main):001:0> '● postgresql@9.3-main.service'.delete("^\u{0000}-\u{007F}")
=> " postgresql@9.3-main.service"

Wow, I officially have no idea what could be causing your original error. Do me a favor a uninstall/reinstall the gem and give it a try then? This exact error was addressed in v0.0.7 but either something didn't install right or we're looking at the same exception but for a different reason.

Also, instead of doing an echo $LANG in terminal, actually put that line in the startup script and run it. The environment in which the scripts are run is entirely different from your normal user shell environment so that could be why. I would bet if you do it there it'll be US-ASCII.

It's actually not set at all in the script env. I added echo "LANG=${LANG}" to the startup script and it outputs LANG=

Unfortunately, reinstalling the gem didnt fix it either. It still needs the manual export LANG line in the startup script.

Hmm, I just checked as well, I also see the same result on my machine.

I'm going to leave this issue open in hopes that we can eventually solve the issue, but I'm not going to go chasing too hard if all it took was setting the LANG in the script before panda-motd is called.

If anyone else has this issue please leave a comment here.

Thanks for your help, @sroche0.

No problem, thanks for writing the tool.

So I actually also am experiencing this problem. The way that I test the gem obfuscates this issue, and I seem to have had the services component disabled in my personal config so it went unnoticed. I'm going to include the export LANG=en_US.UTF-8 in the default script in the Wiki.