Blog

This site is powered by Pharo Smalltalk as web server, Seaside as web framework and Pier as content management system.


Deploying Pier on Ubuntu with Plesk at the german provider 1blu

This tutorial describes how to deploy Pier on an Ubuntu Linux distribution with Plesk at the german provider 1blu. It assumes that you want to install a pier image on an Ubuntu Linux with Apache 2 under a domain called www.YOURDOMAIN.tld.

Start up

VM

      squeakvm
      so.vm-display-null
      so.vm-sound-null

Pier

  • Download the Pier one click image 2.0 (not 3.0!)
  • Copy to the /srv/site folder the followings:
      pier.image,
      pier.changes,
      files/ folder, and
      Pharo10.sources.

Run

  • You can run the image headless by using the following bash script:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          Startet piercms
# Required-Start:    
# Required-Stop:     
# Default-Start:     2 3 4 5 S
# Default-Stop:      
# Short-Description: 
# Description:       
### END INIT INFO
# Author: Przemyslaw Niescior <pubpn@objectspace.net>
# Aktionen

case "$1" in
  start)

    #settings

	USER="www-data"
	VM="/usr/bin/squeakvm"
	VM_PARAMS="-mmap 200m -nodisplay -nosound"
	IMAGE="/srv/site/Pier.image"

	#start the vm

	"$VM" $VM_PARAMS "$IMAGE" &
	exit 0
	;;
 restart|reload|force-reload)

	# No-op

	;;
  stop|\"\")

	# No-op

	;;
  \*)

	# No-op

	;;
esac
:

  • Save this script in /etc/init.d/startpier.sh
  • Create links with the command: update-rc.d startpier.sh defaults 99

Setting up Apache2

  • Go to Plesk Panel and enable Apache modules rewrite, proxy and proxy_http
  • Create the following configuration file .htaccess in your web-directory:

RewriteEngine On
RewriteRule ^/pier(.\*)$ http://www.YOURDOMAIN.tld$1 [redirect,last]
RewriteRule ^/files/(.\*)$ http://localhost:8080/files/$1 [proxy,last]
RewriteCond /srv/site/files/%{REQUEST_FILENAME} !-f
RewriteRule ^(.\*)$ http://localhost:8080/$1 [proxy,last]

Configuring Seaside

  • Go to http://www.YOURDOMAIN.tld/pier/system/management and set the base directory in the section "File Settings" to /srv/site/files.
  • Execute the following code in your pier.image:
       WAAdmin disableDevelopmentTools
  • Save your image and copy it back to /srv/site.
  • Go to the Seaside-Configuration by clicking on "Config" at the bottom of your site.
  • Find "Root Class" and click the button "revert".
  • Accept with OK.

Password protection

If you want to limit access to configuration of your deployed applications make sure that you password protect them. To password protect an application do the following:

  • Go to http://www.YOURDOMAIN.tld/config
  • In Possible Parents select WAAuthConfiguration and click Add (default user is admin and password is seaside).
  • Set your own login and password in the Configuration section below.
  • Click on Save.

Seaside_pass.jpg

Finish

  • Go to http://www.YOURDOMAIN.tld/pier/system/management, set the persistency to "Image Persistency" and click the button "snapshot".
Posted by Przemysław Nieściór at 28 February 2013, 12:21 pm with tags pier, deployment, plesk, 1blu, vServer link

Switch-case in Smalltalk

Smalltalk language does not offer with his standard classes a switch-case mechanism. Here is an easy way to implement such a mechanism.

The first step will be to create a class Switch as subclass of class Object and to define three variables: value, satisfied and response.

Object subclass: #Switch
    instanceVariableNames: 'value satisfied response'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Objectspace.net-Controlling Structures'

The variable value will hold the object for which the switch is made. The variable satisfied tells us, if any of the case conditions are met. The variable response will hold the result of the operation, which will be made in case of fulfillment of the conditions of any case.

Next we define a class method for: which creates an instance of the class Switch.

Switch>>for: anObject
   ^self new value: anObject 

To avoid having to initialize the variable satisfied to false, we define a method isSatisfied, which returns true only if the variable satisfied is true.

Switch>>isSatisfied
   ^satisfied == true 

Now we create methods case:then: and default:

Switch>>case: oneArgTestBlock then: execBlock
   "The oneArgTestBlock must return a Boolean value
   when ==passed the value of the receiver."

   self isSatisfied ifFalse:[
      (oneArgTestBlock value: self value) ifTrue:[
         self response: execBlock value.
         self satisfied: true]].
   ^self response

Switch>>default: execBlock
   self isSatisfied ifFalse: [
	self response: execBlock value].
   ^self response 

And now we can write:

(Switch for: x)
   case: [:value | value = 1] then: ["..."];
   case: [:value | value = 2] then: ["..."];
   default: ["..."]  

For such a simple test block as above, we can create a very useful method in class Switch.

Switch>>caseIs: testObject then: execBlock
   ^self
	case: [:value | testObject = value]
	then: execBlock. 

So our previous example will look like this:

(Switch for: x)
   caseIs: 1 then: ["..."];
   caseIs: 2 then: ["..."];
   default: ["..."]

We can also define an identity version of this method for fast comparing of symbols or classes:

Switch>>caseIdentityIs: testObject then: execBlock
   ^self
	case: [:value | testObject == value]
	then: execBlock.  

And we can simplify searching in collections:

Switch>>caseIsAny: testCollection then: execBlock
   ^self
	case: [:value | testCollection includes: value] 
	then: execBlock. 

All of this looks good, but someone would like it even easier - instead of writing Switch for: aValue simply write aValue switch. To do this we add the switch method to the class Object.

Object>>switch
   ^Switch for: self 

And our previous example can be written as follows:

x switch
   caseIs: 1 then: ["..."];
   caseIs: 2 then: ["..."];
   default: ["..."]  

(pn)

The method switch presented above can also be defined as follows:

Object>>switch
   ^Switch for: self value 

Now it is possible to use the following syntax:

[x\*10] switch
   caseIs: 1 then: ["..."];
   caseIs: 2 then: ["..."];
   default: ["..."]  

Besides, this implementation allows to use an instance of the class ValueHolder in the switch-case structure. The method switch can now be sent directly to such an object.

In the above switch-case mechanism we can also remove the variable satisfied. We will then perform several blocks satisfying the case conditions, just as it does in C.

(wh)

Przemysław Nieściór & Wacław Hołub, 02.06.2002


Sources:

or on GitHub:

Posted by Przemysław Nieściór at 11 June 2012, 12:00 pm with tags switch, case, smalltalk link