Tag Archives: Linux

mosquitto connection refused

Hi all, if you’ve just upgraded mosquitto server on some flavour of linux and wondered why all your mosquitto subscribers and publishers on your network have just started failing, you may have fallen foul of this:

the new mosquitto 2.0 requires a ‘listener’ be configured to the ports required, or else it will only listen to the localhost:1883.

So if all your clients start failing after, edit the configuation and add the following line to the top:

“listener 1883”

See the post here for more information: https://mosquitto.org/documentation/migrating-to-2-0/

Swappiness in linux

Shamelessly stolen from wikipedia because they’re thinking about removing this, as  “Wikipedia is not a howto”. *sigh*.

 

With kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over, it is likely better to use 1 for cases where 0 used to be optimal.

To temporarily set the swappiness in Linux, write the desired value (e.g. 10) to /proc/sys/vm/swappiness using the following command, running as root user:

# Set the swappiness value as root
echo 10 > /proc/sys/vm/swappiness

# Alternatively, run this
sysctl -w vm.swappiness=10

# Verify the change
cat /proc/sys/vm/swappiness
10

# Alternatively, verify the change
sysctl vm.swappiness
vm.swappiness = 10

Permanent changes are made in /etc/sysctl.conf via the following configuration line (inserted, if not present):

vm.swappiness = 10

10 is generally good for ‘I don’t want swapping to happen except if you *really* need it.

 

Varnish weird error

Are you getting a weird error from varnish that you’re having trouble working out? Is it cryptically saying that there’s an issue with your host definition in your VCL?

Expected ID got ';'
 (program line 165), at
 ('input' Line 20 Pos 30)
 .first_byte_timeout = 120;
 -----------------------------#

You need to add a time unit to your timeout definitions — ‘s’ for seconds, ‘m’ for minutes.  Stupid cryptic error is dumbly cryptic. Grrr.
https://varnish-cache.org/lists/pipermail/varnish-bugs/2011-August/003983.html

Varnish nsca logging on systemd system with x-forwarded-for

So, you have a Varnish server running systemd, which is behind a reverse proxy for SSL like nginx, and you can’t work out how to make varnishncsa log IP addresses from a specified header? Well, it’s a bit of a pain in the neck really. You need to override the systemd service file, which is like systemd’s version of the init scripts. Due to it being systemd, this is not just a case of editing a file…

For Debian, you can use the service file below, and paste it into
/etc/systemd/system/varnishncsa.service

Once done, you need to reload systemd’s service listing itself;
$ systemctl daemon-reload

Congratulations, you now have varnishncsa logs including the visitor’s real IP address, as specified by Nginx. Change the name in “{X-Forwarded-For}” to change the header name, for example if you want CloudFlare’s view of the client’s IP address, use “CF-Connecting-IP”

[Service]
 RuntimeDirectory=varnishncsa
 Type=forking
 PIDFile=/run/varnishncsa/varnishncsa.pid
 User=varnishlog
 Group=varnish
 ExecStart=/usr/bin/varnishncsa -a -w /var/log/varnish/varnishncsa.log -D -P /run/varnishncsa/varnishncsa.pid -F '%%{X-Forwarded-For}i %%l %%u %%t "%%r" %%s %%b "%%{Referer}i" "%%{User-agent}i"'
 ExecReload=/bin/kill -HUP $MAINPID

 

Odd Magento / Fishpig / WordPress error

If you get an error like:
Fatal error: Call to a member function select() on a non-object in /home/username/public_html/app/code/community/Fishpig/Wordpress/Model/Resource/Page.php on line 119

Then, check you’ve not just changed a MySQL username, without updating the fishpig configuration, or otherwise Fishpig can’t access the MySQL database for some reason. It seems to store a MySQL login in Magento config. I’ve not yet found exactly where, I’ll update this post with more once I understand more about what it’s doing.

 

It presented as the main Magento site throwing the following error:

exception ‘Zend_Exception’ with message ‘dbModel read resource does not implement Zend_Db_Adapter_Abstract’

 

Which it seems that most everyone will tell you to clear your cache to fix. You *will* need to clear your cache, probably. Just, after fixing the MySQL connection issue.

 

The following line is to make it easier for people googling to find this post:
Fatal error: Call to a member function select() on a non-object in /public_html/app/code/community/Fishpig/Wordpress/Model/Resource/Page.php on line 119 magento fishpig

 

This post my making sure  https://xkcd.com/979/ doesn’t happen from me.

Rfduino Chip vs Thermometer

Well, I’ve now debugged a few issues with my scripts from my last post.
(made them a bit more fault tolerant and actually take notice of $? exit statuses) .
Recap: Temperhum (USB) -> Raspberry Pi -> Xively chart, now also
RFDuino (bluetooth wireless) -> Raspberry Pi -> Xively chart

Tip:  If you’re struggling with the bluetooth on linux giving rx timeout errors (check the syslog if it’s not in the console),
update the software with the following commands:

sudo apt-get update
sudo apt-get upgrade

The Rfduino has been sitting next to my usb Temperature and Humidity sensor for a few weeks collecting data.

IMG_20140514_223244041r

RFDuino and Temperhum

Since it had been both collecting data for a few weeks and sending them to Xively / Pachube / Cosm, I had a quick look to see how closely the readings match.

Rfduino vs thermometerr

The graphs do show correlation, thank goodness, but it looks like the RFDuino’s temperature scale isn’t right. The RFDuino is only updating the graph once a minute whereas the Temperhum is 2x a minute.

I didn’t really expect great accuracy for the RFduino thermometer seeing as it’s measuring from the chip. But this would still be useful in some more basic cases.

I think next on the roadmap for the RFduino is connecting sensors/remote controls (it would be cool to attach my RelaySockets to this and control the 2 connected relays via bluetooth from my Pi and Android smartphone!

 

My Humidity and Temperature sensor

A Temperhum from PCSensor.

A great little bit of kit – once you work out the conversion values for the C++ USB/i2c/HID code that lets linux talk to the thing!

Mythubuntu 12.04 and Radeon 9200

Hi all, I was having trouble installing Mythubuntu 12.04 on an old PC I had lying around.
Mythubuntu is based on Ubuntu 12.04 so if you’re struggling with the ATI Radeon 9200 on there these steps should help.

(Since I have a Hauppuage Nova-T 500 dual freeview pci card from old projects, and a 2tb drive from new ones, I wanted to see about recording some films!)

Basically, when booting it would come up with a garbled, black or blank screen.

If this happens during the livecd boot, preventing you from installing, when you see the logo:

Logo that appears when first booting ubuntu from livecd.

Logo that appears when first booting ubuntu from livecd.

Hit enter, and F6 for other options, select nomodeset, hit enter to enable then Escape and enter to boot.
If operating from a laptop, you might want to try noapic too.

 

In the latest grub setup – grub 2 – the boot menu is hidden, making it near impossible to access.
Might make it look pretty but is major frustrating for troubleshooting!
The script /boot/grub/grub.cfg it uses is supposed to boot in textmode if it has failed to boot, but this does not work.

The fix:

Note: you can login, type

sudo su

and then skip typing sudo with every command below (it gets quite annoying I know!)

  1. To access the grub bootmenu, hold down shift – after all your pc’s bios and add-on cards bios screens have disappeared and until it pops up – it takes a while to appear!
  2. To access the console – textmode, insert the word text and remove ‘splash quiet’ from the kernel options,
    also insert the word nomodeset
    then press F10 or Ctrl-C to boot with the new settings.
  3. Connect to the internet, if using Wired connection you may need to connect (hopefully you connected ok during the install)

    sudo nmcli -p con up id “Wired connection 1”

    If that doesn’t work check your wireless connections names with and edit the above command appropriately

    nmcli con

  4. Install xserver-xorg-video-ati

    sudo apt-get install xserver-xorg-video-ati

    (don’t freak out when you see ‘Removing Mythubuntu-desktop’ it seems to come right in the end.

  5. Create a new link for the X server
    (Not sure why this breaks after the upgrade but it won’t work without this step!!)

    sudo ln /usr/bin/Xorg /usr/bin/X

  6. Edit the default bootmenu script
    Add nomodeset to the default grub bootmenu

    sudo nano /etc/default/grub.cfg

    Change this line near the top:

    GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”
    to
    GRUB_CMDLINE_LINUX_DEFAULT=”nomodeset”
    #”quiet splash”

    The # tells it to ignore this bit, it’s a backup so that we can make it quiet again later. You’ll notice text streaming by as the system boots instead of the cute (Myth) Ubuntu …. logo

    Ctrl-X to exit, type s and Return to save

  7. Update grub

    sudo update-grub

  8. Reboot and Revel in the shinyness

    sudo reboot

I actually ran this command to to start the windows manager, (and I haven’t tried rebooting yet, shhh)

sudo start lightdm

If you have any extra trouble, comment below, check the ubuntu forums and google.
I managed to work this out on my own as I couldn’t find the answer!

 

I also created a script to set the resolution of lightdm at boot, following the guide here:
LightDM Resolution

This did not work as when I started lightdm, the resolution was set higher than I’d set in lightdm, so I don’t think this was part of the fix.
Thankfully it was within my monitors capabilities. I think I set the output name wrong.
I need to figure out the display outputs are available but couldn’t query it from the command line without x running, which seems kinda silly.

Hope this has been helpful!