OpenTechSchool - Javascript for Beginners

(by )

2 month ago I coached at OpenTechSchool’s HTML & CSS for Absolute Beginners workshop. This weekend I once again helped at one of their workshops, this time Javascript for Absolute Beginners.

What should I say? It was again a great experience. It were less learners this time, but the ones that attended where very motivated and eager to learn new things. The material (Day 1, Day 2) was again provided by the OpenTechSchool movement and also translated into German. After just the first day, there were already great programs implemented, e.g. a star system, with rotating planets and moons.

The second day was a little less packed, but again all attendees worked their way through the material, asking interesting question and I did my best to answer them. But sometimes I couldn’t and needed help from the other coaches or even a quick online search to give a correct answer. (Would you know how to describe the difference between null and undefined in Javascript in about 1-2 sentences to a first-time programer?)

This time there was a small lottery. The winner already blogged about his experience: Cool JavaScript stuff I learned at the Open TechSchool workshop.

For this lottery I hacked a small and completely fair(!) winner-picker with the same tools/code also available to the learners. As requested the code is available online in a gist.

A big thanks again to the organizers of the OpenTechSchool Dortmund Team! Spread the word, attend meetups and workshops and use the chance to coach!

Changing the root password in recent SmartOS

(by )

Back in 2012 Jonathan Perkin wrote a little bit about SmartOS and the global zone, why and what in SmartOS is mounted read-only.

Back then /etc/shadow, the file containing the root password, was mounted with write permissions. It is not anymore:

# ls -l /etc/shadow
-r--------   1 root     root         560 May 12 19:51 /etc/shadow

And thus passwd will fail when trying to change the password. But it’s easy to circumvent this. It’s actually a lofs-mount as can be seen:

# mount | grep shadow
/etc/shadow on /usbkey/shadow read/write/setuid/devices/dev=1690008 on Mon May 12 20:05:36 2014

So to change your password use the following:

/usr/lib/cryptpass your-fancy-password
# replace crypt string in /usbkey/shadow
umount /etc/shadow
mount -F lofs /usbkey/shadow /etc/shadow
  1. will create the crypt string of your password. Make sure to remove it from your bash history afterwards
  2. place this string in /usbkey/shadow (it’s the long string between the first two :)
  3. unmount the file in place
  4. remount the right file back in place

And that’s it, the new root password is set.

key=value logs with nginx

(by )

In Six Ways to Make Your Production Logs More Useful @roidrage talked about how to make your logs much more useful. One of the proposed solutions was to use a format that is more structured and thus easier to read: key=value logging. This way it’s easy to parse for a human eye, but a machine will have no problems either. And of course your standard shell tools (with the combination of some basic regular expressions) will still work to find what you want in your logs.

This blog and all of my other sites run on nginx and with nginx it is very easy to use a custom log format. Just define a new log_format, give it a meaningful name and the layout you want. For example I use the following now:

log_format  keyvalue  'time=$time_iso8601 ip=$remote_addr user=$remote_user req="$request" '
                  'status=$status bytes_sent=$body_bytes_sent req_time=$request_time ref="$http_referer" '
                  'ua="$http_user_agent" forwarded="$http_x_forwarded_for"';

Put this in your http {} block and wherever you define a new access log file append keyvalue (or the name you have chosen) like this:

access_log  /var/log/nginx/access.log  keyvalue;

And voilà:

$ tail -1 /var/log/nginx/access.log
time=2014-04-15T18:20:54+02:00 ip=127.0.0.1 user=- req="GET / HTTP/1.1" status=301 bytes_sent=184 req_time=0.000 ref="-" ua="curl/7.36.0" forwarded="-"

If you want to know which variables are available, read the nginx docs.

Update: @rhoml pointed me to a full overview of available variables.

OpenTechSchool - Learn new things

(by )

Last weekend (29./30.03.) I coached beginners some HTML & CSS. This is about my experience.

A while back a friend of mine asked me if I wanted to help at OpenTechSchool Dortmund, coaching programming or to hold a talk. At that time I was a little busy with University stuff like writing exams, but I said I would be very happy to help.

Workshop schedule

Then about a week ago he reached out to me. One of their coaches had canceled and they needed a new one. I immediately said yes. Last friday then we had a short and fun coach meeting where I met the organizers. They worked hard to translate the complete material into German to make it easily understandable. The full material can be found online. It’s not quite perfect but it is a good starting point.

Saturday began quite early and by 11 o’clock the room at ständige vertretung was filled with about 20 beginners ready to start learning HTML & CSS. The OpenTechSchool encourages people to learn at their own pace, so my task was not to teach them but only assist when questions came up. This was a lot of fun for all, it was very interesting and great to see people getting so much fun by learning a new thing, implementing their own ideas and setting their creativity free. Oh, and I also learned a few things (typography can be an interesting topic).

After two full days of HTML & CSS and a very very funny evening in a local bar, the workshop came to an end and results started to show up. All attendees had something done, at least one website was successfully uploaded to the internet, some even worked on their sites after that.

If you want to know more about the OpenTechSchool and what they do go over and read about it. The next beginner’s workshop will be on 24th and 25th of May. Register at Meetup. Maybe I can find the time to be there as a coach as well (if the organizers want me as a coach of course ;)) There are also monthly “Learners Meetups” with talks, discussions and a lot of great people, next one just next week on 9th April.

A big thanks to the organizers Ola, Dennis, Leif, Tobias, Carsten and Hendrik. Another big thanks to the other coaches Lars and Dennis. And of course to all attendees, who had so much fun.

Fixing zfs pool error in zones/dump

(by )

At work we’re using SmartOS, an Open Solaris clone featuring all kinds of cool stuff. One of the best things is the underlying file system: ZFS.

With ZFS it is easy to create, mirror, extend storage pools, it’s also very easy to snapshot pools and backup them using zfs send and zfs receive. In the process of a manual backup of one of the pools today I wanted to see the status of the whole system by using zpool status. This is what it showed:

$ zpool status -v
  pool: zones
 state: DEGRADED
status: One or more devices has experienced an error resulting in data
        corruption.  Applications may be affected.
action: Restore the file in question if possible.  Otherwise restore the
        entire pool from backup.
   see: http://illumos.org/msg/ZFS-8000-8A
config:

        NAME        STATE     READ WRITE CKSUM
        zones       DEGRADED    16     0     0
          mirror-0  DEGRADED    32     0     0
            c0t4d0  DEGRADED    32     0     0  too many errors
            c0t6d0  DEGRADED    32     0     0  too many errors
        logs
          c0t9d0    ONLINE       0     0     0
        cache
          c0t8d0    ONLINE       0     0     0

errors: Permanent errors have been detected in the following files:

        zones/dump:<0x1>

At first this looks a litte bit weird. What is this zones/dump even for? Why is it broken? The answer: Solaris dumps the memory onto the disk on a system crash. I tried googling this error, why it would get corrupt, if the disks are really broken or if it is just a software error.

Turns out this bug is known. We recently upgraded our SmartOS, which brings up this issue. The disk and the pool are not really broken, but simply the data is misinterpreted. To correct it you must replace the dump and later scrub the whole pool again. I executed the following commands to do this (found them in a forum post):

zfs create -o refreservation=0 -V 4G zones/dump2
dumpadm -d /dev/zvol/dsk/zones/dump2
zfs destroy zones/dump
zfs create -o refreservation=0 -V 4G zones/dump
dumpadm -d /dev/zvol/dsk/zones/dump
zfs destroy zones/dump2

This will first create a new file system, swap it in as the dump file system, delete the old one and once again create a new one with the old name and putting it back in place.

In case the dumpadm -d part fails, complaining about the file system being to small, just resize it:

zfs set volsize=20G zones/dump2

See Swap and Dump Volume Sizes for ZFS File Systems.

The scrubbing took 21 hours with our large data set, but it was not noticable in running machines on this host due to its low priority. The final status:

  pool: zones
 state: DEGRADED
…

errors: Permanent errors have been detected in the following files:

        <0x17f>:<0x1>

Well, now the zones/dump:<0x1> is gone. But it still shows an error for the same file system, just that it is not named anymore. We’re scheduling a maintenance soon to reboot the machine. Let’s hope this will clear the error. Otherwise we will replace the HDD.