FreeBSD – Configure a private IP jail

If you use jails (or want to use jails) but your pool of IP addresses is somewhat limited don’t worry. You can fully configure and use a jail in a private IP, and even assign port forwarding from the “outside” network to reach the jail.

First things first, create a loopback interface clone and assign it an IP address:

ifconfig lo1 create
ifconfig lo1 inet 10.1.1.1/32

To make this live across reboots add the following lines to /etc/rc.conf:

cloned_interfaces="lo1"
ifconfig_lo1="inet 10.1.1.1 netmask 0xffffffff"

Now, use ezjail to create and configure a new jail and assign this internal IP address. If you start the jail now you will be able to access it, but in the jail itself you will not be able to access the outside world… this is where NAT comes in.

There is at least 2 options, the natd daemon + ipfw or the pf route. I opted for the pf route simply because the configuration is much more simple (but if you are more pro-efficient with natd and ipfw probably it’s the best bet).

As always be careful when messing with a firewall, specially if you are working on a remote server, as you can lock yourself out of your own server. I usually set up an at job that reboots to the previous state in half an hour or so to test everything before committing the changes permanently to rc.conf (to start and stop services with no rc.conf entry you can use the onestart/onestop option).

This is the most economical version of /etc/pf.conf (adjust the external interface and the jail IP (the first two lines):

ext_if="em0"
JAIL_SRV="10.1.1.1"

set skip on lo0
scrub in all

nat on $ext_if from lo1:network to any -> $ext_if

pass all

and fire up pf

service pf start

and now from inside the jail you can access the world. Actually, the FreeBSD manual (in it’s current writing) states an additional step, that is to enable the sysctl gateway_enable=”YES” option to nat work, but I didn’t enable it on two machines running FreeBSD 10 and is working perfectly. In set-ups with natd + ipfw you have to enable it for sure, on old FreeBSD versions with pf I just don’t know… but if you can’t access the world from within the jail enable this would be on top of my list.

To make this permanently just have to add to /etc/rc.conf

pf_enable="YES"

Now, that you have the jail all set-up, It’s about time to expose a service to the world (let’s say for example a HTTP server running clear and ssl – ports 80 and 443), you just need a tweak in /etc/pf.conf:

ext_if="em0"
JAIL_SRV="10.1.1.1"
PORT_WWW="{80,443}"

set skip on lo0
scrub in all

nat on $ext_if from lo1:network to any -> $ext_if
rdr pass on $ext_if proto tcp from any to $ext_if port $PORT_WWW -> $JAIL_SRV

pass all

You can jail services without using external IPs, assign HDD space via ZFS or virtual disk files, set CPU core(s) affinity, or fine grained memory and CPU limits via rctl.

Pretty cool!

Keeping (some) productivity while depressed

First things first. Depression is complex, with different types, stages and strength. If you are in a state called clinical or major depression: don’t get out of bed, don’t have the will to take care of yourself, don’t eat, don’t sleep properly. If you are in this stage, well, fuck the productivity, get help. You don’t believe me now, but things will eventually get better IF you get help. Also, be very careful about other people, don’t do anything that can screw up friendships and relationships, because you are in a mind frame that other people just don’t understand. Be careful and take care.

So, just the minimum essential stuff of your life is a heavy burden, but still there are bills to be payed at the end of the month. This is my holding on playbook, and as always i have no responsibility if you apply any of these guidelines and everything goes very wrong.

1 – accept the fact that you are not 100%. This is very important, don’t deny and accept this simple fact, it gets you much more grounded and support your choices. Depression can last for months or years, so take it like any other chronic illness, adapt and learn to live with it.

2 – also accept the fact that you will work less. I worked an average of 12h a day (sometimes weekends included) and now a weekday average of 4h is average, 6h is good and 8h is excellent. Adapt your life to this reality, don’t do “wishful thinking”.

3 – try to be flexible in your work schedules. In many work situations this is not doable at all, if you work at a store or in a factory or something like that skip to the next guideline. But if you can, be flexible, i mean really flexible. I just don’t mean getting half hour late and going out also after hour later. Let’s be honest, your sleep and mental patterns are all fucked up. Do you think that you will produce any good mental work at 9am when at 5am you were staring at the ceiling? It’s much more productive to be working at 5am instead of looking at the ceiling and resting at 9am instead of being an office zombie. In the last months i have get things done probably at each and every hour of the day.

4 – this last guideline, brings up also guideline #1. Don’t be ashame and explain your situation to your boss/partner/manager/etc. It’s really important they understand that you are not lazy, or trying to fuck things over at work. Look, if you were able to do, is really awkward to them that out of the blue you aren’t able to perform the same way now. Ultimately the reaction is that you just don’t care less about working and the company/business. It’s your responsibility to make them understand what’s going on.

5 – break tasks into really tiny and achievable bits. Each work day, try to finish up some of the tasks and take a moment to contemplate. Don’t make extensive time and project planning, or if someone earns their money doing some nice Gantt charts for your time, just don’t give a shit about it. Focus on your next tiny task.

6 – tell yourself on the start of the work day several times, I AM A GREAT ________ (fill in with your work). I CAN DO THIS. In my case, i say to myself: I am a great programmer. I can do this.

7 – exercise, plenty and hard. It seems counter intuitive, with the low energy levels to punish yourself even harder. But bear with me, the low energy levels come from your brain (except if your depressed from some clinical condition) and not exercising is just letting your body decay that in turn will lead to a more weak mind, can you see the negative loop? Also it will release endorphins and dopamine that relieve your brain pain. Another benefit that i account for is that will drift your mind from your sad toughs loop, when beneath an heavy barbell you don’t feel sad, you just focus on lifting that shit away from you. Again, when running and tired and 5kms away from your car or house, you don’t feel sad at all, you just focus on getting there.

8 – keep up friendships, specially with the good vibes kind of persons that bring something positive to your life. The bad vibes, problematic kind of friends, keep them away. Remember there is a Yin there is a Yang, there is Winter there is Summer, there is sour there is sweet, night and day, there is work and there is fun.

9 – get outdoors, specially when the Sun is shining. Go for a walk, go to the beach, go and eat your favorite food, go for a drink, just go outside. Move to a walking friendly neighborhood. This is a personal rule, don’t stay indoors for more than 24h.

10 – avoid listening to sad music, watching sad movies, reading sad books, etc. Some are masterpieces in their own right, but let them be for other times. If you can, skip the evening news on TV, 90% is just garbage, completely biased to negativity not to positivity (too much stories about unemployment, crime and gore).

11 – don’t give up, when things look really dark just hold on to your core tasks, core values and keep going forward. Don’t give up on work, don’t give up on good friendships, don’t give up on love. Be optimistic. Tomorrow is another day. And after, another and so on, and someday all of your being will come together again, and by that time you will come up stronger as ever.

UPDATE:

I just realized a very important fact. Ask yourself, what is the opposite of depression? It’s not happiness. It’s mania. And what is mania? It’s a state characterized by euphoria, great excitement, delusions and hyper activity. It’s doing stuff, lots and lots of it. It’s an over optimistic state, when you are in overdrive (as the opposite of the stuck in depression) just doing all kinds of stuff, maybe some that you will later regret…

But the point is, when depressed, probably it’s a good bet to focus less in happiness, stop asking how can i get happy again, and shift this mind set and start asking how can i get this stuff done, how to summon your drained resources and focus on the next little task ahead.

Because in a split second, it’s gone.
Ayrton Senna

Body image – cultural brainwashing

Look at this picture:

gijoefigureThis is the “evolution” of the GI Joe action figure from the sixties to the latest iteration. From an average Joe, to a well toned Joe, passing trough the bodybuilder Joe and ending in the extreme Joe.

This was all good if it was a all about the toy, the problem is that the toy is a reflection of the society. And is not only the toy, but also in movies, advertising, sport and general media. There you go, the collective cultural brainwashing of a dis-formed body image as a society imposed goal.

I say dis-formed because (for the 99,99% of us mortals) it’s either unachievable, or achievable trough unhealthy options, long term unsustainable, and just non functional bulky body. In the information age, is rather sad to see most of young guys at the gym training hard for bulk and mass, not for health or functional gains.

Now you mix this set of mind, with the fast pace “I want it now”, there is no time to loose, Internet age, modern world. A time that hard work, wait for results, seed, feed and wait to grow are all old-school. And is the perfect formula for substance abuse. First things first, protein supplements in form of powders, bars, gels. This is a $11.5 billion (USA data only) industry in 2012 and could well deserve a post on its own… then you figure out that the big guy holding the can is using other stuff: steroids, human growth hormone, insulin, etc…

Come on, why not do it? Most of the cool guys at Fast and Furious do it, Rocky did it, Conan did it and was California governor, and even a couple of the big guys at the gym do it. And they look somehow alike GI Joe extreme, and it’s cool, and big is better, and they get the anorexic girls, and they are popular, and, and, and…

At the information age, smart and well educated persons are willing to risk their health in the name of this cultural imposed body image model. In my opinion (well, this is my blog) is just time to break this non-sense, to start an awareness campaign, kind of the anti anorectic girl campaign in the 90s. To promote an healthy and achievable body image and stop this collective brainwash backed up by the supplements industry.

Personally i choose life. I’m more and more into crossfit exercises, functional lifts with compound movements, own body weight exercises, catabolic anabolic balance, deep breathing and relaxing. Will trade, anytime, anywhere the superficial muscle grow for long term balanced core strength.

Tune-up a Ikea Expedit shelve with a LED Strip

IKEA ExpeditI was tired of looking into my plain, dull, boring, tedious, monstrous Ikea Expedit shelve in the living room. And, it seems that the new trend at the independent furniture shops (ok, the Pakistani at Lisbon downtown) is to apply LED strips to all kind of furnishings: beds, tables, chairs, stools, sinks, whatever… and boom!!! Eureka, the aha moment, why not leave the bed and table alone, but cheer up my shelve! Also it made sense in a functional way, since at mid-light room I can barely see the stuff that i get from the inner guts of it.

Next day, was shopping day for LED strips in Ebay the global marketplace. Now bear with me, the shopping process is crucial for a good development of your project. There are several decisions you must take. First, the length of strip that you need, for the full IKEA Expedit we are talking about 1.47cm * 5 = 7.35m (and give yourself some cut margin and error margin). Next the LED type, the protection rating and color. For the LED types there are two mainstream options 3528 and 5050. They get their numbers because the dimensions of the chip, 3.5mm * 2.8mm for the 3528 and 5.0mm x 5.0mm for the 5050. So the 5050 is bigger than the 3528, are substantially brighter, with an average of 18 lumen Vs 6 lumen, but also more power angry 0.24W vs .08W. So, for decorative lighting your best bet should be the 3528 and for functional lighting or bright environments you should go for the 5050. Also, take care of the number of LEDs per meter, it should be clear now that a meter of strip with 60 3528s should output the same amount of light that of a meter with 20 5050s (but the first will look much more smooth)… now for the protection rating, you can check the full spec here, but i will break it down for you. The first number is for solid particle resistance and the second for the liquid protection. The common IP20, stands for 2 (protection against fingers or similar?!) and 0 (not protected against water), other common available IP in LEDS strips is IP65 (6 – No ingress of dust; complete protection against contact and 5 – Water projected by a nozzle (6.3 mm) against enclosure from any direction shall have no harmful effects). Usually higher the IP, higher the cost of the strip. For me, with 2 young, active and curious cats in the house, the choice was obvious (IP65)… finally, the color is mainly a question of personal taste, but if you want to change the color on the fly, the way to go is a RGB 5050 LEDs strip as each chip has the 3 main colors that combine into the color that you want (or some psychedelic effects).

This guide is for the 4×4 IKEA Expedit shelve, but is easy adaptable to other piece of furniture.

You will start with:
– 2 rolls of 3028 IP65 warm white
– a transformer (more on this later)
– wire for the connections, don’t worry too much about the thickness as the flow of power will be limited, but worry to get a flexible wire, the flexible the better
– electric block connector (for parallel connections, if series you don’t need this but a little more solder..)
– insulation tape
– a virgin IKEA expedit shelve

Tools:
– a multimeter to check continuity
– a soldering iron and some solder
– a wire stripping tool, or a knife or scissor or use or teeth (don’t use the teeth)
– a screwdriver for the electric block connectors
– a X-Acto knife
– a ruler to check out the dimensions is not a bad idea

Other stuff needed:
– a bottle of beer, so when you get thirsty don’t leave the workstation

You start to cut down five 1.47m segments Expedit Suppliesout of the LEDs rolls. The LEDs strips have a scissor mark that repeats itself along the way after some number of LEDs (mine was between each 3 LED). So look for the nearest mark and cut it with precision on the middle. It’s important that you cut cleanly at the middle as will be easer in the soldering step.

Now, you must decide what kind of connection you should do. You can go parallel or series. For parallel you have the advantage of less soldering to do, if one section stops to work the others will continue to, but you will use more wire, block connectors, and it will be a pain to hide the electric circuit if the fitment is in the middle of the room. The series will use less wire, no block connector, it will be easier to hide completely in the back side of the fitment, but much more soldering to do, and if one of the strips go bad (or the connection between) the upstream will also not work.

You should keep in mind a very important detail about LED strips. When you cut a piece in the pre-designated cutting zones, there is a transistor right before the connectors. This transistor will automatically close the circuit for you if there is no upstream continuity. So if you connect in series and connect a 12v transformer (in the right polarity) to the first LED segment it should light up, you don’t need to close the circuit in the other side. If you connect another segment to the first one (again check the polarity, the LEDs strip should have plus and minus markings) it behaves the same, lights up without the need of closing the circuit at the far end.

Expedit Wiring Diagram

Now, for the “funny” stuff, to solder the circuit. With the X-Acto knife remove the protection material (epoxy or silicone) above the solder points. Then with the hot iron melt way the remaining of the protection material. Drop a bit of solder into the solder points, then drop another bit into the end of the stripped wire. Then press and hold the wire against the solder point, and heat it up until both bits of solder melt and fuse. A quick demonstration video:

When it’s all done and fitted, means that is time to calculate the power consumption, and transformer requirements. Each LED uses 0.08W and one meter has 60 LEDs, for the sake of simplicity we will round the 1.47m segments to 1.5m. So each segment has 90 LEDs, 0,08W * 90 = 7.2W per segment. At 12v it gives (7.2 / 12) 0.6amps per segment. For 5 strips in parallel, the total output is 3amps.

To be safe the transformer should output 12v and 3amps (if it’s rated in Watts should be 36W). If you use a less powerfull transformer (let’s say a 1 amp) it can heat up and meltdown. If you feed the circuit with less voltage it will the lights will dim, and as you step down the voltage, eventually it will not light at all. The cost per hour of usage at full throttle is pretty cheap, as 36W/h at 0.20 cents the Kw/h sums at a cost of 0.0072 cents hour….

If all goes well the final result should be this:

expedit_leds

Exercice program – 12 weeks

After a major disruption in life… I’m starting again to take care of my body, some jogging (pain free!!), some gym, and a bit of open water swimming and surfing.  I think our body is one of our greatest treasures and should be well cared for. Besides, the physical is the the first pillar of a solid human foundation. The four pillars are: physical, mental, emotional and spiritual. As they are all chained together, when you work and improve one, it has a positive impact on the others too.
So now is the perfect opportunity to set a goal, and my goal is to keep the current weight (about 75Kgs) but to lower my body fat percentage. By the scientific method of seeing pictures of bodies with different percentages and comparing with myself, i can’t be far from the 25% percent. So the goal is around 15% body fat percentage.

The Exercise Program

Disclaimer, this is my own program. I spent some time experimenting what works for me and what doesn’t. Also, it addresses lots of personal variables, as time, more vs less crowded equipments at the gym, available items, hate of abdominal crunches, etc… you can take some ideas, but beware I’m not in any way an exercise expert, so don’t do anything that can hurt your health.

Weekly Program: 4 sessions (running, swimming, 2 times at gym). The order is irrelevant, and can change from week to week.

1 – A 10k, easy sub 60m run. But with some sprints to put the heart in high revs to burn off the accumulated particulate (actually the purpose of the sprints is to become more efficient runner by working above the lactate threshold). This is the primary cardio workout.

2 – A 45m swimming session in the pool. Just to swim non-stop at an easy pace. This is the main stretch, balance and relaxing training session. It also activates the muscles that can be left behind in the gym.

3 – A couple sessions in the gym. Maximum 50m each session.

Day 1
5m warmup: easy rowing/ciclyng and joints rotations

Shoulders (light weight as warmup follow-up)
Lateral Raise DB – 2×10 (lateral deltoid)
Alternating Front Raise DB – 2×10 (anterior deltoid)

Chest
Bench Press 3 sets of 12,10 and 8
Incline bench press, 3 sets of 12,10 and 8
Flies, 3 sets of 12,10,8 reps or
Dips, 3×10

Triceps
CGBP EZBar 4×10
French Press 4×10

ABS
Myotatic Crunch and
Vacuuming
Superset of 3×10

Day 2
5m warmup: easy rowing/ciclyng and joints rotations

Shoulders (light weight as warmup follow-up)
Lateral Raise DB – 2×10 (lateral deltoid)
Rear Lateral Raise DB – 2×10 (posterior deltoid)

Back
Cable pulldown 12,10,8
Pull-ups 15 (in many sets has needed)
Seated rows 12,10,8
Deadlifts 3×10

Biceps
Stand Up or Seated Curl 4×10
EZ Bar Curl 4×10 or
Preacher BB Curl 4×10
Hammer DB Curl 3×10

ABS
Myotatic Crunch and
Vacuuming
Superset of 3×10

Actually the hidden and true goal, is to stick with this the 12 weeks. To have the strength and discipline to follow this calendar (even in the no good mood days, brain off days, rainy days, etc). In every way, with or without visible results, it will build a stronger version of myself by doing it. So help me God.

W1: R G2 G1 S24
W2: R G2 G1 S40
W3: R G2 G1 S10 (Xmas Week)
W4: G2 R G1 S26 (New Year Week)
W5: G2 G1 R S30
W6: G2 G1 S30 R
W7: G2 S24 G1
W8:

I never saw a wild thing sorry for itself. A small bird will drop frozen dead from a bough without ever having felt sorry for itself.

David Herbert Lawrence