Dealing with /var/run in systemd unit files

Day 28 in the #vDM30in30 Image source: https://flic.kr/p/y1DUPj So previously I blogged about about how to ensure a /var/run directory exists before a systemd service starts, using the ExecStartPre steps to ensure the directory exists. ExecStartPre=-/usr/bin/mkdir /run/jmxtrans/ ExecStartPre=/usr/bin/chown -R jmxtrans:jmxtrans /run/jmxtrans/ I took the idea from a blog by Jari Turkia. However, I made the rookie mistake of not checking the comments to see if things had changed and there was a better way, since the original post was written in 2013. ...

November 28, 2016 · 2 min · Peter Souter

Sublime Plugins

Day 27 in the #vDM30in30 I started off as a Java developer, so I was used to Eclipse and Intelij, quite heavy IDE’s with lots of assistance. After moving away from Java and into Ruby, I noticed one of the other developers was using TextMate, and it seemed much nimbler and easier to get things done. However, there were a few annoying things that about Textmate at the time (circa 2012~), such as Textmate crashing when you looked at large files. At the time we had a few larger JSON fixtures (not massive, 50-100kb or so) we were using for testing. A bit of a pain. ...

November 27, 2016 · 3 min · Peter Souter

Quickly testing with dply.co

Day 26 in the #vDM30in30 A quick one this time, talking about a fairly recent service, https://dply.co/ What is it? dply is a pretty cool service for creating free temporary Linux servers. Essentially, it’s just a GUI in front of DigitalOcean. It allows you to quickly create a temporary droplet server (1CPU , 512MB RAM, 20GB SSD). Servers are free for 2 hours and expire after that time (you can add a Credit Card to keep them around for longer) ...

November 26, 2016 · 2 min · Peter Souter

The Puppet Resource Abstraction Layer (RAL) Explained: Part 4

Day 25 in the #vDM30in30 Image from https://flic.kr/p/6t59b So, we’ve talked about the RAL, getters, setters and the resource command. Now let’s talk about implementing a RAL interface of our own. swap_file type and provider I ended up implementing a RAL layer in my swap_file module, mainly as an exercise in figuring out how types and providers work. It looks like this: Puppet::Type.type(:swap_file).provide(:linux) do desc "Swap file management via `swapon`, `swapoff` and `mkswap`" confine :kernel => :linux commands :swapon => 'swapon' commands :swapoff => 'swapoff' commands :mkswap => 'mkswap' mk_resource_methods def initialize(value={}) super(value) @property_flush = {} end def self.get_swap_files swapfiles = swapon(['-s']).split("\n") swapfiles.shift swapfiles.sort end def self.prefetch(resources) instances.each do |prov| if resource = resources[prov.name] resource.provider = prov end end end def self.instances get_swap_files.collect do |swapfile_line| new(get_swapfile_properties(swapfile_line)) end end def self.get_swapfile_properties(swapfile_line) swapfile_properties = {} # swapon -s output formats thus: # Filename Type Size Used Priority # Split on spaces output_array = swapfile_line.strip.split(/\s+/) # Assign properties based on headers swapfile_properties = { :ensure => :present, :name => output_array[0], :file => output_array[0], :type => output_array[1], :size => output_array[2], :used => output_array[3], :priority => output_array[4] } swapfile_properties[:provider] = :swap_file Puppet.debug "Swapfile: #{swapfile_properties.inspect}" swapfile_properties end def exists? @property_hash[:ensure] == :present end def create @property_flush[:ensure] = :present end def destroy @property_flush[:ensure] = :absent end def create_swap_file(file_path) mk_swap(file_path) swap_on(file_path) end def mk_swap(file_path) Puppet.debug "Running `mkswap #{file_path}`" output = mkswap([file_path]) Puppet.debug "Returned value: #{output}`" end def swap_on(file_path) Puppet.debug "Running `swapon #{file_path}`" output = swapon([file_path]) Puppet.debug "Returned value: #{output}" end def swap_off(file_path) Puppet.debug "Running `swapoff #{file_path}`" output = swapoff([file_path]) Puppet.debug "Returned value: #{output}" end def set_swapfile if @property_flush[:ensure] == :absent swap_off(resource[:name]) return end create_swap_file(resource[:name]) unless exists? end def flush set_swapfile # Collect the resources again once they've been changed (that way `puppet # resource` will show the correct values after changes have been made). @property_hash = self.class.get_swapfile_properties(resource[:name]) end end Now, there’s a bunch of weird stuff in there, that to be honest even know I only vaguely understand… ...

November 25, 2016 · 5 min · Peter Souter

The Puppet Resource Abstraction Layer (RAL) Explained: Part 3

Day 24 in the #vDM30in30 Image from https://flic.kr/p/DY38HH So, we’ve talked about how the RAL is a getter and setter, but let’s talk about a lesser known feature of puppet that uses the RAL: The puppet resource command. The puppet resource command is basically a CLI for the RAL. Hey, it used to even be called “ralsh”, for RAL Shell. What it’s doing is using that instances method from before, and running it on the system, and returning the current state as valid Puppet code. ...

November 24, 2016 · 2 min · Peter Souter