7. Pre-built Actions

Elsware comes with quite a few actions that are ready to go.

7.1. SSH login action

This uses pxssh to login to a server over ssh, and saves the logged in session with the clients object. The ssh session object is an instance of elsware.ssh.SSHSession - which is actually just a wrapper around pxssh with shortcuts.

7.1.1. Action class name

Registered as ‘ssh_login’.

7.1.2. Action parameters

'login':{
        'action_class':'ssh_login',
        'server':'admin@slicehost',
        'password':'mypassword', #optional
        'password_in_opt':'ssh_password', #optional
}

7.1.3. Transaction rollback

Logs out of the active ssh session.

7.2. SSH logout action

Logs out of an active ssh session.

7.2.1. Action class name

Registered as ‘ssh_logout’

7.2.2. Action parameters

'logout':{
        'action_class':'ssh_logout',
        'server':'admin@slicehost',
}

7.2.3. Transaction rollback

Logs into the server through ssh.

7.3. Apache Actions

The apache actions help you stop, start, and restart an apache server. It requires a logged in ssh session, and some additional information in your servers’ configuration:

config={
        'servers':{
                'admin@slicehost':{
                        'ip':'111',
                        'user':'admin',
                        'apache':{ #required
                                'apachectl':'/usr/bin/apachectl' #required
                                'sudo':True|False, #optional
                        }
                }
        },
        #...
}

7.3.1. Running Apachectl as Sudo

Optionally apache actions can run with sudo.

7.3.2. Password Searching

Passwords are searched for in the traditional order {(as described here)}, but passwords are also searched for inside of the apache configuration for a server:

config={
        'servers':{
                'admin@slicehost':{
                        'ip':'111',
                        'user':'admin',
                        'apache':{
                                'apachectl':'/usr/bin/apachectl'
                                'sudo':True|False,
                                'password':'', #optional
                                'password_in_opt':'', #optional
                        }
                }
        },
        #...
}

7.3.3. Action parameters

Each apache action should define it’s parameters like this:

'restart':{
        'action_class':'apache_restart',
        'server':'admin@slicehost',
}

7.3.4. Apache restart action

The apache restart action runs apachectl restart on the logged in ssh client.

7.3.4.1. Action class name

Registered as ‘apache_restart’.

7.3.4.2. Transaction rollback

This action will not perform a rollback, as the opposite of restart is restart.

7.3.5. Apache stop action

The apache stop action runs apachectl stop on the logged in ssh client.

7.3.5.1. Action class name

Registered as ‘apache_stop’.

7.3.5.2. Transaction rollback

Starts apache on rollback.

7.3.6. Apache start action

The apache start action runs apachectl start on the logged in ssh client.

7.3.6.1. Action class name

Registered as ‘apache_start’.

7.3.6.2. Transaction rollback

Stops apache on rollback.

7.4. Git update action

The git update action cd’s to the target directory on the server, and runs “git pull origin master”. It requires a logged in ssh session.

The repository must already exist on the server - this will not clone a repo for you.

7.4.1. Action class name

Registered as ‘git_update’.

7.4.2. Action parameters

'update':{
        'action_class':'git_update',
        'server':'admin@slicehost',
        'dir':'/var/www/vhosts/projects/site/',
}

7.4.3. Transaction rollback

Runs git reset --hard -q COMMIT. Where COMMIT is the head commit object, before the update.

7.5. SVN update action

The svn update action cd’s to the target directory on the server, and updates the repo.

The repo should already exist on the server.

7.5.1. Action class name

Registered as ‘svn_update’.

7.5.2. Action parameters

'svnup':{
        'action_class':'svn_update',
        'server':'admin@slicehost',
        'dir':'/var/www/vhosts/project/',
        'force_checkout':True|False
}

7.5.3. Force checkouts

By default, the –force option isn’t used. Instead, it cd’s to the target directory, runs rm -rf ./*, and then runs an svn update.

There are still linux distributions that come with subversion 1.4.2, which does not include the –force option. If you know your subversion install supports –force, you can turn on “force_checkout”.

7.6. SCP push action

The SCP push action pushes a local directory, up to a server over scp. It requires an available ssh session - over ssh it copies the target directory on the server, as a backup. Then the scp transfer is initiated.

When the action is finalized, the temporary copy on the server is deleted.

7.6.1. Action class name

Registered as ‘scp’

7.6.2. Action parameters

'scppush':{
        'action_class':'scp',
        'server':'admin@slicehost',
        'localdir':'/Users/aaronsmith/projects/project',
        'serverdir':'/var/www/vhosts/projects/project'
}

7.6.3. Transaction rollback

On rollback, the temporary copy of the original directory on the server is restored.

7.7. SCP push zipped action

The SCP push zipped action is pretty much the same as the scp push action, but this one zips up the local file, or directory, pushes it up to the server, then unzips it on the server. It can save a little time and bandwidth.

7.8. FTP push action

The FTP push action pushes a local file or directory up to a server over FTP.

7.9. Email django admins

The email admins action is specific to django. Generally, you want to put it last in your action chain. If any messages, or exceptions have accrued into self.deployment.messages, an email is sent to settings.ADMINS with those messages.

7.9.1. Action class name

Registered as ‘email_admins’.

7.9.2. Action parameters

'email':{
        'action_class':'email_admins',
        'subject':'The subject for my email',
        'from':'me@example.com',
}

7.11. Raise test exception action

The raise exception action is used for testing transactions. For example, you could define an action chain like this:

...
'slicehost':{
        'actions':(
                {'transaction':('login','git_update','exception','logout')},
        )
}
...

This will cause the action runner to ‘login’, ‘git update’, then raise an exception, which will trigger transactions.

7.11.1. Action class name

Registered as ‘exception’.

7.12. HTTP request action

The http request action makes a request to a desired url - optionally given data it will POST to the url. This is a good way to notify, or perform some other actions that some other scripts provide. For example, you may have a php script that restarts a mail server, or sends out emails to a mailing list.

7.12.1. Action class name

Registered as ‘request’.

7.12.2. Action parameters

'request':{
        'action_class':'request',
        'url':'http://www.google.com/',
        'data':{}, #optional
}