Wednesday, May 08, 2013

Update MoinMoin from 1.9.5 to 1.9.7

This is the general steps for updating moinmoin from 1.9.5 to 1.9.7

  1. Stop web server or standalone process
  2. backup wiki instance (eg. mywiki or instance1)
  3. backup moinmoin installation path
  4. if there is customized logo, backup it as well (eg. moinmoin.png)
  5. delete *.pyc or *.pyo
    find  -name *.pyc -exec rm {} \; 
  6. download moinoin1.9.7 and install to existing path
    python setup.py install --prefix 
  7. replace moinmoin.png if necessary
  8. if using web server, remember to change the static path from "/moin_static195" to "/moin_static197"
  9. start web server or standalone process
  10. double check the version by http:///SystemInfo

Monday, February 18, 2013

Setup Trac on Raspberry Pi as a Wiki and Issue Tracking Tool

Trac with GIT

Trac is a wiki and issue tracking tool. There are other choices such as redmind and mantisbt. However, Trac is the most suitable one for running on Raspberry Pi because:
  1. it is run by python, which is installed by default for raspbian. (php and ruby are not required)
  2. it is relatively light weight. It can use sqlite as the database, rather than MySQL or PostgresSQL.
  3. it can be run in standalone mode, without using apache or lighttpd. (although I will still use lighttpd to 'proxy' Trac)
  4. It supports modern version control tool such as Subversion and GIT. (redmine also supports, but again, it's not that light weight)
  5. with making use of virtual environment (virutalenv), you can setup Trac without using a privilege account.
  6. it is a mature product and many organizations are using it (http://trac.edgewall.org/wiki/TracUsers)

Install and setup Trac

First, make sure virtualenv is already installed. (apt-get install virtualenv)

Remove a file completely in GIT

GIT is a great version control tool. I was a CVS and SVN users but I think GIT is even more powerful. Perhaps I can write something about GIT but now I want to share an experience: How to remove a file completely from GIT.

There is an internal db in GIT. Once your add and commit codes into the repository, the info will be store and the great thing is that you can check out the file at any version. However, I did an stupid thing - I hard coded some personal information (eg password) in a file and commit it to the repository. It won't be a problem if you are the only developer of the project.  But if you need to share the code by cloning the repository to the others, your information can be retrieved, even you delete it in filesystem.

So I did some quick search and find a solution: just runt the following command to remove the history and file:

git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch " HEAD

Make sure you make a copy to some places out of the GIT repository. Then you can copy the file back and add it as a "fresh new" file.

PS. As a better practice, don't hard coded any thing that cannot be shared in a repository !!

Tuesday, January 29, 2013

Getting Serial Number of HP-UX (works on RP5470 - HP11i PA-RISC)

HP-UX 11i is now pretty old but it is surprised that there are still a lot of companies using it. Though it is stable but hardware failure is something unpreventable. Once you found hardware fault, you probably need to call vendors (HP or others) to diagnostics.

A typical question will be "what is your server model? OS? Serial number?" Here is the quick answer:

OS Version: uname -a
Model: model (yes, simple?)
Serial Number: no single command to get it. but the information can be retrieved in cstm:
echo "sel path system\ninfolog\nexit"|cstm|grep "System Serial Number"

eg.
# uname -a
HP-UX zzzzzzzzz B.11.11 U 9000/800 106424635 unlimited-user license
# model
9000/800/L3000-8x
# echo "sel path system\ninfolog\nexit"|cstm|grep "System Serial Number"
   System Serial Number...: xxxxxxxxxx
 

Thursday, November 29, 2012

Remote access to your Raspberry Pi with ssl/ssh multiplexer

One big advantage of Raspberry Pi is its low power consumption. I can power on it 7x24 and remote it at anytime (of course, assumed your router is also on). SSH from internet to your Pi is simple, by just forwarding port 22 or making the Pi is the default DMZ. However, some places only allows you to visit port 80 or 443, or you have to connect to the internal via a proxy server, which also blocks every ports but 80/443.

Since port 443 is an exception, why don't we set the SSH service to listen to it? Just modify /etc/ssh/sshd_config and add a line "Port 80" or "Port 443". It does work, but wait, what about if the Pi also serves as a Web Server with SSL enabled? If you choose 443 to serve SSH, then you can't have your web server to use SSL at 443. So how to solve this situation? Here is one of the possible approach.

Monday, November 26, 2012

Create a Soalris 8 zone (32bit) to a container

Last time I had successfully created a flar image from an old Solaris 8 server (ref). Now I have to setup a zone of Solaris 10 container and install the image into it. The overall idea is clear and easy. Normally just create the zone configuration, and install it from a "flar" image.

1. Create zone configuration

root@sol10 # zonecfg -z z_sol8
z_sol8: No such zone configured
Use 'create' to begin configuring a new zone.
zonecfg:z_sol8> create -t SUNWsolaris8
zonecfg:z_sol8> set zonepath=/pool/zone/sol8
zonecfg:z_sol8> set autoboot=false
zonecfg:z_sol8> set ip-type=shared
zonecfg:z_sol8> add net
zonecfg:z_sol8:net> set address=192.168.123.123
zonecfg:z_sol8:net> set physical=nxge0
zonecfg:z_sol8:net> end
zonecfg:z_sol8> verify
zonecfg:z_sol8> commit
zonecfg:z_sol8> exit


Next install the zone from the flar image:       

Thursday, November 22, 2012

Create a Wiki (Moinmoin) on Raspberry

Moinmoin is a very good Wiki application without using a DB. It is very fast, with easy syntax and I recommend to use it as a quick knowledge base for home or SME usage.

 This guide is to install moinmoin on a Raspberry Pi and make it accessible via Lighttpd (using fastcgi). It is assumed a virtual host is available for this wiki (eg. http://wiki.example.com )
The moinmoin program will be installed at /usr/local/moinmoin_engine while the instance will be installed at another place (eg. /usr/local/moinmoin_instance1. )
  1. Download the latest source (1.9.5 as of this moment) at http://moinmo.in
  2. extract the tar ball to a temp place (eg. /tmp)
  3. under the source path, run
    python setup.py install --prefix=/usr/local/moinmoin_engine
  4. mkdir the instance path
    mkdir /usr/local/moinmoin_instance1
  5. copy the following directories from "engine" to "instance", and change the ownership to the lighttpd user:
    cp -r /usr/local/moinmoin_engine/share/moin/data /usr/local/moinmoin_instance1
    cp -r /usr/local/moinmoin_engine/share/moin/underlay /usr/local/moinmoin_instance1
    cp /usr/local/moinmoin_engine/share/moin/config/wikiconfig.py /usr/local/moinmoin_instance1
    cp /usr/local/moinmoin_engine/share/moin/server/moin.fcgi /usr/local/moinmoin_instance1
    chown -R www-data:www-data /usr/local/moinmoin_instance1
  6. modify the moin.fcgi, locate the following lines:
    # a1) Path of the directory where the MoinMoin code package is located.
    #     Needed if you installed with --prefix=PREFIX or you didn't use setup.py.
    #sys.path.insert(0, 'PREFIX/lib/python2.3/site-packages')
    sys.path.insert(0, '/usr/local/moinmoin_engine/lib/python2.7/site-packages')
    
    # a2) Path of the directory where wikiconfig.py / farmconfig.py is located.
    #     See wiki/config/... for some sample config files.
    #sys.path.insert(0, '/path/to/wikiconfigdir')
    sys.path.insert(0, '/usr/local/moinmoin_instance1')
    
    ...
    
    ## this works around a bug in flup's CGI autodetection (as of flup 1.0.1):
    #os.environ['FCGI_FORCE_CGI'] = 'Y' # 'Y' for (slow) CGI, 'N' for FCGI
    os.environ['FCGI_FORCE_CGI'] = 'N'
    
    ...
    
    # Is fixing the script name needed?
    # Use None if your url looks like http://domain/wiki/moin.fcgi
    # Use '' if you use rewriting to run at http://domain/
    # Use '/mywiki' if you use rewriting to run at http://domain/mywiki/
    #fix_script_name = None  # <-- adapt="adapt" as="as" class="anchor" here="here" id="line-24" needed="needed" span="span">
fix_script_name = ''# <-- adapt="adapt" as="as" here="here" needed="needed" pre="pre">
  • Next prepare virtual host by appending the following block /etc/lighttpd/lighttpd.conf:
    $HTTP["host"] =~ "wiki\.example\.com" {
            
      fastcgi.server += ( "/" =>
          ((
            "socket" => "/tmp/moin.socket",
            "min-procs" => 1,
            "max-procs" => 2,
            "check-local" => "disable",
            "bin-path" => "/usr/local/moinmoin_instance1/moin.fcgi",
            "fix-root-scriptname" => "enable"
          ))
      )
    
      alias.url += ( "/moin_static195" => "/usr/local/moinmoin_engine/lib/python2.7/site-packages/MoinMoin/web/static/htdocs")
    
    }
  • Restart Lighttpd and the your own wiki is just born! 

  • For more information about user and administration guide, please refer the HelpContents.

    PS: So here is the wiki running on my Raspberry Pi: http://wiki.jessed121.us/ . You can walk around and feel it.

    Install Lighttpd, PHP5, MySQL on Raspberry Pi

    To run a 'typical' server on Raspberry Pi, a Web server is necessary. If possible, it can run application (by PHP5, Java, Perl, Python, etc...). Apache may be the most famous web server, but here I choose Lighttpd is it is not as big as Apache. In fact, a lightweight server is more suitable. Also, it will use FastCGI to run PHP and Python, I will list out what applications/ services to be run on this server.

    Finally Mysql is also a popular DB. At the beginning I don't want to install it as there may be a huge overhead on the Pi. In fact, some embedded DB such as sqlite would be a better option. However, there are still applications which only official support Mysql, so at last I decide to install it and hopefully can fine-tune it later.

    So here is the steps...

    Install Lighttpd and PHP5

    1. Login as root
    2. create the user and group "www-data"
    3. Install the following packages:
      • apt-get update (get the latest repository)
      • apt-get install lighttpd php5-cgi
    After installation, check the /etc/lighttpd/lighttpd.conf
    include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
    it will includes setting under /etc/lighttpd/conf-enabled. Make sure there is something like "fastcgi" and "fastcgi-php". (The settings can be fine tuned afterwards)
    # ls /etc/lighttpd/conf-enabled/
    10-fastcgi.conf  15-fastcgi-php.conf

    Install Mysql

    just install the packages "mysql-server", "php5-mysql"

    Failed to exclude directories when running flarcreate on Solaris 8

    When I tried to prepare a flash archive (flar) from an old Solaris 8 physical machine, I wanted to exclude two directories (say, /one and /two). I checked the syntax from web (and the man page), it should be:

    flarcreate -n -c -S -R / -x /one -x /two
    where -c is enable compression, -S is ignore size stats, -R is the root path

    However, the directories /one and /two are still in the flar !

    After doing some investigation and research from the web, it is believed that there is a bug of this script of the current version. Since it's too old and I don't want to apply any patch on it, I'd rather modify the script a bit in order fulfill my requirement:

    Tuesday, November 20, 2012

    Weather information from openweathermap.org JSON API by Python

    The openweathermap.org offers JSON API to query weather information around the world. It is not difficult to use python to call the API, parse the JSON and gather the information.

    Since all the request are from web, it'd better to prepare a simple function to fetch the HTML/JSON from the site:

    import urllib2, json

    def fetchHTML(url):
        req = urllib2.Request(url)
        response=urllib2.urlopen(req)
        return response.read()

       
    Remember it is just for a quick and dirty approach. In real case we should handle exceptions (such as URL unreachable, network not found, etc)

    Now we are ready to call the API. First of all we need to know the "id" of a City. http://openweathermap.org/data/2.1/find/name?q=<CITY>