keskiviikko 15. toukokuuta 2013

Creating .tar

In computing, tar (derived from tape archive) is both a file format (in the form of a type of archive bitstream) and the name of a program used to handle such files.

I would describe tar as a zip file. It packages everything in one file. For example if I have my html page in one folder I can tar the folder in one file and then untar it somewhere else.

To create an archive of a directory and its contents you would type the following and press enter:

$ tar -cvf name.tar /path/to/directory

and to untar

$ tar -xvf name.tar


GitHub is a web-based hosting service for software development projects that use the Git revision control system.

I am still trying to get GitHub working with my Linux. 

Install git:
$ sudo apt-get install git
go to project folder
$ git init
$ git add .
$ git commit

Then create Github account
Generate SSH Keys and add to your account

Then it should be this easy but I can't figure out what is wrong

$ git remote add origin
$ git push -u origin master

I get error repository not found. Blah. Help me ?

After that I tried with these:

$ git remote add origin ssh:// 
$ git push origin master 
$ git branch --set-upstream master origin/master 
$ git pull && git push

 and I managed to push two files to my git repo !

Final task, my own module. Puppet - Tomcat module

Our final task was to create our own module for puppet. I decided to do something which is useful for myself. Because we did a school project with tomcat I wanted to install tomcat with my module. First we download the tomcat tar file, then extract it, remove the tar, change configuration file from template and finally start the service.

I am using virtualbox on 64bit windows 7 with 12GB ram + AMD 1055t 6 core processor. Linux used for testing, Xubuntu 12.10

I did the work in small pieces. First I created puppet test module which placed simple txt file in temp folder. After that I did downloading, then extracting, removing, template and startup.

Tomcat obviously need Java. So I started by creating openjdk module. As you can see from my modules tree, there are three modules. One for testing, one for java and one for tomcat.

The java module is very simple. Its only task is to install java developement kit. The code goes like this:

 class java {
package { 'openjdk-7-jdk':
 ensure => installed,

And to run it:
$ sudo puppet apply --modulepath modules/ -e 'class {"java":}'

Now we have jdk installed and tomcat is ready to be deployed. Of course I had to download tomcat beforehand to get the template file from conf folder which has the tomcat-users.xml file. My tomcat init.pp goes like this:

class tomcat(
$source = '',
$package = 'apache-tomcat-7.0.40.tar.gz',

exec { 'download-apache-tomcat-7.0.40.tar.gz':
command => "wget $source",
cwd => "/home/$id",
path => '/usr/bin/',

exec {'extract-apache-tomcat-7.0.40.tar.gz':
command => "tar -xvf $package", 
cwd => "/home/$id",
path => '/bin/',
require => Exec['download-apache-tomcat-7.0.40.tar.gz'],

exec {'remove package':
command => "rm $package", 
cwd => "/home/$id",
path => '/bin/',
require => Exec['extract-apache-tomcat-7.0.40.tar.gz']

## TODO change variable for shnigi

file {'/home/shnigi/apache-tomcat-7.0.40/conf/tomcat-users.xml':
ensure => file,
content => template ('tomcat/tomcat-users.erb'),
require => Exec['extract-apache-tomcat-7.0.40.tar.gz'],

## TODO fix startup

exec {'start service':
command => "sh",
cwd => "/home/shnigi/apache-tomcat-7.0.40/bin/",
path => '/bin/',
require => File['/home/shnigi/apache-tomcat-7.0.40/conf/tomcat-users.xml']


$ puppet apply --modulepath modules/ -e 'class {"tomcat":}'

The problem is that the needs probably sudo command and I don't know how to bypass that. Everything else is working correctly, because if I run the startup manually tomcat manager gui shows correctly.

$ cd /home/shnigi/apache-tomcat-7.0.40/conf
$ sudo sh

Now surf to http://localhost:8080 and see the tomcat manager-gui =)


Puppet mumble server module

I wanted to create TeamSpeak 3 module for my raspberryPi but teamspeak is not supported on ARM so I chose to create mumble server instead. It seems that the mumble-server configuration file doesn't accept my edits so this should basically work, but I was too lazy to figure it out why for example the welcome message didn't change.

Inside puppet folder:

Under my modules folder I created "mumble" folder and inside manifests there is the init.pp file. Inside init.pp:

class mumble {

    package { 'mumble':
    ensure => installed,

/Desktop/puppet$ sudo puppet apply --modulepath modules/ -e 'class {"mumble":}'

And it worked.

Inside my mumble folder beside manifests I create folder named templates. There I want to copy mumble server configuration file from /etc

$ sudo cp /etc/mumble-server.ini /home/username/Desktop/puppet/modules/mumble/templates

And now back to the init.pp file

class mumble {

package { 'mumble-server':
ensure => installed,
before => File ['/etc/mumble-server.ini'],

package { 'mumble':
ensure => installed,

file { 'mumble-server.ini':
path => '/etc/mumble-server.ini',
ensure => present,
content => template('mumble/mumble-server.ini.erb'),
require => Package ['mumble-server'],

service { mumble-server:
require => Package ['mumble-server'],
ensure => running,
notify => Service["mumble-server"],


$ sudo puppet apply --modulepath modules/ -e 'class {"mumble":}'

And it worked.

perjantai 10. toukokuuta 2013

Linux hosts

This is something that we went through very fast on last class and I don't remember everything. Anyway under /etc there is a file named "hosts" I found my computers IP address there with my computers name. I added a line with same IP and www name like this

Then I installed apache2 and pointed my browser to and the web page showed !

Refreshing memory, testing puppet

It's been a long time since a used puppet and I wanted to refresh my memory a little bit. I created a simple puppet code that creates a file in tmp folder to see if puppet is working correctly.

Start always by updating repositories

$ sudo apt-get update
$ sudo apt-get -y install puppet

Preparations. I created puppet folder hierarchy on my desktop.

$ pwd
$ mkdir puppet
$ cd puppet
$ mkdir modules
$ cd modules

and here we can create our modules. Because this will be a test file I create a folder named test.

$ mkdir test
$ cd test
$ mkdir manifests
$ cd manifests
$ nano init.pp

class test {

file { '/tmp/test':
ensure => file,
mode => 777,
content => "foo is so bar",

cd to puppet folder and then apply.

$ puppet apply --modulepath modules/ -e 'class {"test":}'

$ warning: Could not retrieve fact fqdn
notice: /Stage[main]/Test/File[/tmp/test]/ensure: defined content as '{md5}082ba698ca7aa38660ca953b78f87b40'
notice: Finished catalog run in 0.09 seconds

And now if you check tmp folder there is a new file.

torstai 2. toukokuuta 2013

Good site to learn or refresh memory - SQL Zoo

Sql zoo has real sql server and there you can train your sql skills or just refresh memory with only web browser, nothing else needed.

keskiviikko 1. toukokuuta 2013


$ sudo apt-get install -y curl

$ curl localhost

$ ifconfig

$ curl

Curl can print websites to terminal for example.

Puppet modulepath command

Inside puppet folder create modules folder and inside modules folder goes all the modules, like apache2 folder, sshd folder etc...

Then run this command for example from

puppet apply --modulepath modules/ -e 'class {"apache2":}'