troubleshoot

Quick tips to kill an application on Raspberry Pi

When you are running and testing a web server (e.g cherrypy) on Raspberry Pi, and there is an error in your codes. You did not shutdown the server nor kill the application properly. You fixed the error and reload it. Tadaa! You get an error saying that the port is not freed and you do not know what to do! Solutions on the internet say “find the app Process ID (PID)”… but how exactly should you find it out of no where??

Or you are testing your new raspberry Pi camera. Opps it hangs and it is on forever. You cannot turn it off, you cannot use it for another test. How to kill it??

Try this:

pgrep the-app-name
E.g. pgrep python

This will return you the PID number (4 digits) of that app (e.g 4908)
Then type:
kill 4908

Raspberry Pi is now good to go for another test. 😉

Web Application Lesson 1

So i have been hearing bad experiences from seniors about this particular module offered to the final year student, Web Design and Application. It was said to be a time-consuming module and the professor has a high expectation on the students.

However I was kind of shocked when the professor actually is a very friendly and helpful person. Perhaps they were talking about some other professors?

Anyway, I installed XAMPP on my Window 7 today. Faced some problems that I am going to note them down.

For Windows:

1. Download XAMPP Portable Lite 1.8.3 PHP 5.5 ZIP file from here.

2. Extract it and move the files to Desktop.

3. Double-click on setup_xampp window batch file. Wait for it to initialize and complete.

4. Run xampp-control application.

5. Start Apache and MySQL. I’ve got errors while starting them!! >> what I did to solve them

– Port 80 in used by system >> change to Port 8000 instead (At Apache, click on “config”>httpd.conf, search for “Listen 80”, change it to “Listen 8000”, save.)

– Apache stopped unexpectedly. >> I stopped MySQL service under Administrative Tool>Service but it doesn’t help. Check for other application that might be using Port 80 (e.g Dreamweaver) but I couldn’t find anything (in fact, I don’t know what else).

– MySQL path in used >> Uninstall the previously installed MySQL.

Finally, I stopped Web Deployment Agent Service and changed it to “Manual start”. Only then I could start MySQL on XAMPP.

The professor said, the best way of learning is to be active and engaged. Do not be scared to ask questions and to clarify. We make mistakes in order to learn. There is nothing wrong to copy but you have to modify it. One nice thing I like about the professor is that he give chance (first warning) to students.  At least if you make mistakes unknowingly, you could change for better.

 

SD card Format Failed

I was all excited about my new Raspberry Pi , Gert board and Arduino Board. They have been there in the box for weeks and I finally took the first step to write the Raspbian Image into my new 16Gb SD card following the guide on the Official Raspberry Pi page.

1. I downloaded the SD Association Formatting Tool from here, installed and ran it.

2. I inserted my SanDisk 16Gb into my laptop built-in card reader.

sandisk 16gb sd card

SanDisk 16Gb SD card

3. Set “Format Size Adjustment” option to ON as shown below.

sd card formatter

4. Clicked on Format and this was what I got: ” The Memory Card is write-protected. Please release the write protect switch.”

sd card formatter write protection error

So, as usual, i searched that on Google and some of the solutions that I have tried are:

1. Paste some tapes over it (as taught here or videos like this)

2. Use a software (USB write-protected) (like here)

3. Press the switch (as taught in most forums / support)

None of the above works.  So i contacted the SanDisk support. They do not seem to have encountered such problem before… and the technician mentioned : “SanDisk does not support the memory card to used as the boost device for the OS image.”

So I am stuck and still waiting for the support.

Other stuffs I tried:

– I couldn’t write any data into it.

– it works fine for my Canon camera.

– I can read the image files in it (image taken using the camera)

– i could not delete the file (there is no delete option and even if i press on DEL button on my keyboard)

I think I should get a Toshiba SD card instead.  : /

R-Pi Server up and running again! (change to static IP)

Fresh in the morning, i reinstall web2py from Web2Py webpage to my home directory ( /home/pi) and run the following:

cd /home/pi/web2py
sudo python2.6 web2py.py

I can start server at 127.0.0.1 (localhost) but not my public IP. It encountered an error:

ERROR:Rocket.Errors.Port8000:Socket 10.0.0.189:8000 in use by other process and it won't share

Meh, can’t find any solution from the web.

So i set my Raspberry Pi IP address to static such as follow:
(ref: Using a Static IP Address)

$ sudo nano /etc/network/interfaces

Change the line that reads

iface eth0 inet dhcp

to

iface eth0 inet static

Below this line enter the desired settings:

address 10.0.0.132 # a static IP address of your choice
netmask 255.255.255.0 # from here onwards, it depends on your router settings
network 10.0.0.0
broadcast 10.0.0.255
gateway 10.0.0.100

For the network mask, broadcast address and gateway, type:

$ ifconfig

or

ipconfig

in your same network window command prompt.

CTRL+O to save and CTRL+X to exit.

Then from your same network computer, try to ping to the new static address you just set by typing in the command prompt:

ping

You can do the same thing on Raspberry Pi as well and ping to your same network computer.

Then i reinstall web2py using the following codes which does not require me to run the web2py.py everytime i want to start the server:

sudo su

wget http://web2py.googlecode.com/hg/scripts/setup-web2py-ubuntu.sh
chmod +x setup-web2py-ubuntu.sh

./setup-web2py-ubuntu.sh

Remember to set an admin password when prompted!
Then go to a browser and type:
https://
for my case, https://10.0.0.132
then click “Admnistrative Interface” and it will prompt you for a your password!
And there you go! server up and running! But i am still wondering why must I install web2py… by right, after reinstalling apache, it should give me “It works!” or something. :/

Mozilla Firefox on Linux Debian?

Previously, i was following through a tutorial at Killer Web Development and i encountered a problem while trying to use Selenium… because I only have Iceweasel and not Firefox. So, here’re my experiences in finding the answer: Will update when i try something new! :s

6/3/2013
1. Well, thank goodness i found an answer for my Firefox and Iceweasel problem here.

First, you need to remove the existing Iceweasel package

apt-get remove iceweasel

To use Linux Mint’s Debian package repo, add the following line to your /etc/apt/sources.list file:

cd /etc/apt
nano sources.list

add the following line:

deb http://packages.linuxmint.com debian import

Then, just run:

apt-get update
apt-get install firefox-l10n-en-us

And FAILED.
E: unable to locate package firefox-l10n-en-us

Err http://packages.linuxmint.com debian/import armhf Packages
404 Not Found

😦

2. Same goes for this:
apt-get remove iceweasel
echo -e "\ndeb http://downloads.sourceforge.net/project/ubuntuzilla/mozilla/apt all main" | tee -a /etc/apt/sources.list > /dev/null
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com C1289A29
apt-get update
apt-get install firefox-mozilla-build

3. I tried to download the latest Firefox onto my Raspberry Pi, but the

download just won’t start on Midori. Hmm, has been unable to download

since days ago i guess.
Nevertheless, i downloaded firefox for linux from here

http://www.mozilla.org/en-US/firefox/all/
and transfer the files to R-Pi using Core FTP LE.

Then, i followed the instructions in another reply under the same forum thread, and tried to copy the downloaded file to /opt

$ cp firefox /opt

cp: omitting directory
The command cp is by default copies only files and if we try to copy a

directory it will throw the above error.

To copy a directory using “cp” all we have to do is add the option “-r”

which means recursively copy all the files from the source directory to the

destination directory. i.e.

cp -r dir1 dir2

Anyway, i still have the bz2 file so,

sudo cp firefox-19.0.tar.bz2 /opt

(without sudo, permission denied)

And yes, copied successfully.

Extract it using:

$ cd /opt
$ sudo tar -jxvf firefox-19.0.tar.bz2

Change the permissions of the file:

$ chown -R root:users /opt/firefox # OPERATION NOT PERMITTED

$ chmod 750 /opt/firefox

Note that the user should be a group member of “users”

$ usermod -a -G users username

Create a symbolic link

$ ln -s /opt/firefox/firefox /usr/bin/firefox

Delete firefox-19.0.tar.bz2 from /opt
cd /opt
sudo rm firefox-19.0.tar.bz2

Conclusion: stuck at unable to change owner. but i doubt it is already under the root ownership. However, i still cannot run the functional_tests.py. some errors to do with selenium still. Anyway, i am going to skip the step for the mean time.

Some useful reference:

To copy files, you use the cp command. The following will copy file to file2. Note that if file2 doesn’t exist, it’ll be created, but if it exists, it’ll be overwritten:
$ cp file file2

There aren’t any undo commands in the Linux CLI, so accidentally overwriting an important file would probably make you pull your head off. The risk of doing so is smaller if you use the -i option (“interactive”) with cp. The following does the same as the above, but if file2 exists, you’ll be prompted before overwriting:

$ cp -i file file2
cp: overwrite `file2'? n
$

So it’s a good idea to use the -i option whenever you’re dealing with important files you don’t want to lose!

If you want to copy file into directory dir1:
$ cp file dir1

The following would do the same as the above, copy file into dir1, but under a different name:
$ cp file dir1/file2

You can also copy multiple files into one directory with a single command:
$ cp file1 file2 file3 dir1

Note that if the last argument isn’t a directory name, you’ll get an error message complaining about it.

The mv command can be used for moving or renaming files. To rename a file, you can use it like this:
$ mv file file2

If file2 doesn’t exist, it’ll be created, but if it exists, it’ll be overwritten. If you want to be prompted before overwriting files, you can use the -i option the same way as with cp:

$ mv -i file file2
mv: overwrite `file2'? y
$

To move the file into another directory:
$ mv file dir1

If you want to rename the file to file2 and move it into another directory, you probably already figured out the command:
$ mv file dir1/file2

The rm command is used for removing files and directories. To remove a file:
$ rm file

If you use the -i option, you’ll be prompted before removing the file:
$ rm -i file

You can also delete more files at once:
rm file1 file2

Be careful with the rm command! As I already told you, Linux doesn’t have any undo commands, and it doesn’t put files into Trash where you can save them later. Once you’ve deleted a file, it’s bye-bye!

Killer Web Development Walkthrough 3

 An App for a Pitch

 

Let’s move on to the next section of Killer Web Development. We are going to create an application from the command line, and not through the web2py interface.

 

1. Creating a Pitch App

 

Creating the pitch app confused me a bit because I didn’t install web2py following his tutorial, remember? So I have no idea on where is my web2py.py file located.

 

$ cd /your/web2py/folder  # on Windows use backslashes

$ ./web2py.py -S pitch   # web2py.exe on Windows and web2py.app on OS X

I spent some time searching for “how to find a file on Linux” and finally I found some clues of using “find”.

 

$find / -name 'web2py.py'

It searched for a while and found its directory – /home/www-data/web2py/web2py.py

 

So I typed in

cd /home/www-data/web2py

./web2py.py -S pitch   (no idea what is -S, couldn’t find it on web)

Now it is time for Mercurial.

 

“In the terminal go to the directory of the pitch app; create a repository; then create a .hgignore-file; add files to the repository and make your initial commit:

$ cd applications/pitch

$ gedit .hgignore

Line 1 is misleading because it should be the complete directory.

For my case:

 

$ cd /home/www-data/web2py/applications/pitch

 

Then at $ /home/www-data/web2py/applications/pitch $ type in
gedit .hgignore

A gedit file will be created. I typed in as instructed but realized that it could not be saved. Yes, I am not the super user!

So, I should type in sudo gedit .hgignore at the terminal. Now, another gedit file is created but without the index 1 2 3 etc at the front when the codes are typed in. The file is saved. Interestingly, this reminds me of Chemistry! Hg is mercury periodic symbol.

 

Again, at the next few command in the terminal, “sudo” has to be included at the front;

 

sudo hg init

sudo hg add .

sudo hg commit -m”Initial commit”

–                    no username supplied. Well seems like the .hgrc file in the previous section comes to use here? I saved it in home/www-data/web2py/applications/pitch (since it says save in home directory).

–                    still the same though. May be I should save it with the web2py pitch file.

–                    Could not save the file as I do not have the permission to save the file in that directory.

–                    Try to save in /home/ – no permission too

 

Found this under the comment: Hg Init

More things to read up here!

 

So in the end, I use the terminal to open up a new file.

 

cd /home

sudo gedit .hgrc

 

I typed in the username and such and save it.

 

Now, try out the hg commit. It is still the same. Well then, till tomorrow!