code: def ensure_state_dir(daemon_dir)
      if not File.directory? daemon_dir then
        begin
          Dir.mkdir(daemon_dir)
        rescue Exception => ex
          $stderr.puts "Failed to create state dir: #{daemon_dir}; message:\n" + ex.message
          exit 1
        end
      end
      if not File.writable? daemon_dir then
        $stderr.puts "State dir is not writable: #{daemon_dir}"
        exit 1
      end
    end
docs: Ensure that the var dir exists and is writable
  
   @raise [SystemExit] on error