     }
 
     do_rebuild(dir, site)
-    FileSystem.subscribe(watcher)
+    unless(is_nil(watcher), do: FileSystem.subscribe(watcher))
 
     {:ok, state}
   end

    IO.puts("Removing temporary directory \"#{site}\"...")
    File.rm_rf!(site)
    IO.puts("Shutting down...")
    Process.exit(watcher, :shutdown)
  end

  @spec do_rebuild(binary(), binary()) :: :ok

  @impl GenServer
  def init({dir, site, portnum}) do
    false = Process.flag(:trap_exit, true)

    watcher =
      case FileSystem.start_link(dirs: [Path.absname(dir)]) do
        {:ok, pid} -> pid
        :ignore -> nil
      end

    state = %{
      watcher: watcher,
