Broken Trust – An Ubuntu upgrade gone wrong

 Linux  Comments Off on Broken Trust – An Ubuntu upgrade gone wrong
Apr 242016
 

When doing the regular updates to my Ubuntu laptop this weekend, I got prompted about an upgrade to version 16.04 (I am on 15.10 currently).
As all updates and upgrades have been smooth and without any problem before, I gladly pushed that button.
In retrospect, I should have been more careful.
The upgrade as such went without any hassle, even though it took quite some time, but no errors or any other messages shown.

It all started when login in the first time.
After entering the password on my account, the desktop is briefly shown with a pop up message about some System program problem detected, then immediately back to login screen.
No chance to read the complete message, nor to interact with the pop up buttons.
Same thing if I try the Guest login.

To catch this picture I had to set the phone camera to burst mode.
Ubuntu1604_login_problem

But doing CTRL + ALT + F1 to get a tty1 console, and I can login on my account.
So far so good, but what do I do now?

First thing first. Hook up an external USB disk, mount it, and backup the files I absolutely do not want to lose.
It is at times like these, you start to wonder when you made your last backup, and was that a complete backup or did I miss something.
This action was taken just to be safe, if I will end up in having to do a complete re-installation on the machine.
I really hope not to end up in that situation.
But as the saying goes, "Hope for the best. Prepare for the worst".

Scouring the net on the login loop problem, it seems to have happened before to people upgrading to other versions (14.04).
One of the solutions I found is.
mv .Xauthority .Xauthority.bak
and then reboot.
But that did not help on my computer. Obviously a solution for another problem.

Searching for the "System program problem detected", and found this to disable the reporting of program problems. Let's see if it helps somehow.
Remove all crash logs, and disable apport.
sudo rm /var/crash/*.crash
sudo vim /etc/default/apport
Change 'enabled=1' to 'enabled=0', restart system.
But this did not help either.

Continued searching, and found someone stating it could be video driver problem (again). Try,
sudo apt-get purge nvidia*
Doing this, I got a question on restart on how to proceed with graphics settings. I chose low quality for now.
I still get the 'system program problem detected' pop-up, but I can enter the desktop.

Finally able to login to the desktop, I notice that WiFi is not working any longer. Wonder what else has stopped working.
After some investigation.
lspci -knn | grep Net -A2
nmcli -p c
nmcli -p g
nmcli dev wifi
lshw -C network
It all looked okay. Ended up just de-selecting the Broadcom WiFi driver in Additional Drivers. Reboot. Then choosing that BCM driver again.
Viola! WiFi is working again. No good explanation on why it works, just happy it does.

While in the Additional Drivers, I also selected the Nvidia graphics driver again. And to my joy, I still am able to login.

Well that actually makes me think I am finally upgraded to Ubuntu 16.04 with everything working.

ISP Watcher

 Linux, Python, Raspberry Pi  Comments Off on ISP Watcher
Dec 062015
 

After waiting for several years, we finally got fiber internet connection two months ago.
Sadly in these two months we have had three occasions when we had no connection to internet at all.
Last time, a couple of days ago, it was out for more than 24 hours!
This is way worse than I expected, and much worse than the old ADSL connection we had before.
On the good side is, that when we actually have connection, it works really good.

But to have better statistics on the connection reliability I made a small python program.

#!/usr/bin/python2 -tt
# Joakim Wesslen

'''
Check internet connection and log result to file
'''

"""
The MIT License (MIT)

Copyright (c) 2015 Joakim Wesslen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

"""

import sys
import time
import urllib2
import socket


logfile = "ispwatcher.txt"
loop_delay_minutes = 30
seconds_per_minute = 60

urls = [
'www.dn.se',
'www.sds.se',
'www.svd.se',
'www.cnn.com',
'www.bbc.co.uk',
'www.dmi.dk',
'www.nrk.no'
]


def getdatetime():
	'''Get date time string'''
	return time.strftime("%Y-%m-%d_%H:%M:%S")


def check_url(url):
	'''check url connection'''
	try:
		response=urllib2.urlopen('http://' + url, timeout=10)
		return True
	except urllib2.URLError as err: 
		pass

	dt = getdatetime()
	s = "Error: {}: {}".format(dt, url)
	print s
	write_result(dt, s)
	return False


def check_urls(urls):
	'''check list of urls'''
	results = []
	for url in urls:
		res = check_url(url)
		results.append(res)
	return results


def calc_result(results):
	'''
	calculate the result of check_urls.
	if one url is accessible, we are connected.
	'''
	if True	in results:
		result = "connected"
	else:
		result = "disconnected"
	return result		


def write_result(dt, result):
	'''write result string to file with datetime'''
	s = "{}: {}".format(dt, result)
	print s
	with open(logfile, "a") as txt_file:
		txt_file.write(s + "\n")


def wait_minutes(minutes):
	'''wait some minutes'''
	time.sleep(minutes * seconds_per_minute)


def get_lock(process_name):
	'''make sure only one instance exists'''
	global lock_socket
	lock_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
	try:
		lock_socket.bind('\0' + process_name)
	except socket.error:
		print "Already running"
		sys.exit()


def close_lock():
	'''release the lock'''
	global lock_socket
	try:
		lock_socket.close()
	except socket.error:
		print "close_lock exception!"


def main(args):
	try:
		while True:
			dt = getdatetime()
			results = check_urls(urls)
			result = calc_result(results)
			write_result(dt, result)
			wait_minutes(loop_delay_minutes)
	except KeyboardInterrupt:
		print 'Stopped by user'
		close_lock()
		sys.exit(0)


if __name__ == '__main__':
	get_lock('ispwatcher')
	sys.exit(main(sys.argv[1:]))

The program checks internet connection two times per hour, and writes the result to a file.
I put it on a Raspberry Pi, connected directly to the router, and also set up a cron job to make sure it runs.
The cron job starts the script every half-hour, and is done as:

00 * * * * /home/pi/ispwatcher.sh
30 * * * * /home/pi/ispwatcher.sh

The shell script is simply starting the python program.

As you can see the python program makes sure only one instance is running, so this setup should be okay I hope.
Let's see what the result will show.

No mouse needed

 Linux  Comments Off on No mouse needed
Feb 092012
 

In my quest for using the computer mouse as little as possible, I thought I had come up with a great idea.
Why not implement a keyboard mouse, using the windows key and arrow keys for navigation.
But then my second thought was, this must already exist.
Sure enough, after some searching on the net, I found this link
http://www.linuxquestions.org/questions/linux-newbie-8/how-to-use-keyboard-as-mouse-266229/

Here is the essence of the link in short.

Shift + NumLock to activate numpad as keyboard mouse.
1,2,3,4,6,7,8,9 to navigate
”5” left mouse button
-” & ”5” right mouse button
”*” & ”5” middle mouse button

It will take some time to get use to, but at least it exists as an alternative.

Linux Monitoring continued…

 Linux  Comments Off on Linux Monitoring continued…
Feb 032012
 

As I stumbled upon an interesting monitoring tool in an article I read, I wanted to write down what I needed to do in order to get it installed properly on my Ubuntu 10.10 laptop.

The tool is glances version 1.3.7, and can be found here glances1.3.7@github. The page has a nice description on how to install, but it didn't work directly as is on my machine.

This is what I did.
First get the tools required by glances. This is what actually made the install work properly.

sudo apt-get update
sudo apt-get install pkg-config build-essential autoconf automake python libstatgrab-dev python-all-dev
sudo apt-get remove python-statgrab
wget http://ftp.uk.i-scream.org/sites/ftp.i-scream.org/pub/i-scream/pystatgrab/pystatgrab-0.5.tar.gz
tar zxvf pystatgrab-0.5.tar.gz
cd pystatgrab-0.5/
./setup.py build
sudo ./setup.py install

Then get glances itself.

wget https://github.com/downloads/nicolargo/glances/glances-1.3.7.tar.gz
tar zxvf glances-1.3.7.tar.gz
cd glances-1.3.7
./configure
make
sudo make install

When that is done the tool is started by running the glances.py file, which is located in the src folder.

./src/glances.py

Linux monitoring

 Linux  Comments Off on Linux monitoring
Jan 292012
 

As my Dell laptop with Ubuntu 10.10 felt really slow the other day, I began to wonder what tools were available to monitor performance, except for the usual top and ps commands I already knew about.

This is a list of the result of my little search of these kind of tools (in no aspect to be regarded as complete).

top - The program provides a dynamic real-time view of a running system.
htop - interactive process viewer.
atop - AT Computing's System & Process Monitor.
iotop - simple top-like I/O monitor.
ps - report a snapshot of the current processes.
iostat - Report Central Processing Unit (CPU) statistics and input/output statistics for devices, partitions and network filesystems (NFS).
sar - Collect, report, or save system activity information.
nmon -systems administrator, tuner, benchmark tool.
lsof - ls of open files.
netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
ss - another utility to investigate sockets.
iptraf - Interactive Colorful IP LAN Monitor.
Nagios - Server And Network Monitoring.
strace - trace system calls and signals.
/proc - linux kernel info.
# cat /proc/cpuinfo
# cat /proc/meminfo
# cat /proc/zoneinfo
# cat /proc/mounts