Close inlet valves and chimney hatches. Use water or a fire extinguisher if the fire has spread outside the flue. You should leave the job of putting out the fire in the flue to the fire service, but if they cannot get to you quickly, you can try to control the fire with a powder extinguisher while you wait.
If you discover a chimney fire, you must close all the valves on the stove and any hatches in the chimney. If there is no fire in the fireplace, you can also close the chimney damper. If there is a fire in the fireplace, you must not close the damper. That would send all the smoke into the room.
If the flue passes through the floor of the next storey, it may come into contact with timbers and other flammable material. If there is a fire in the flue, these materials can catch fire. So you should keep a special watch out for smoke at these points, not forgetting lofts and cellars. If you discover that the fire is spreading at the point between two storeys, you can try to put it out with water or a fire extinguisher.
You should leave the job of putting out a chimney fire to the fire service. Phone the emergency services on 110. If you are in a cabin, or the nearest fire service cannot get to you quickly, you can try to control the fire with a powder extinguisher while you wait. Carefully open the soot door at the bottom of the chimney and aim the extinguisher nozzle into the chimney. Press the trigger, but only release a small amount of powder. Close the door again. Repeat this if the fire starts up again.
Remember that you must never put yourself in danger. You must always get out before it becomes dangerous to be inside.
After the fire, the chimney must be inspected by the fire and chimney sweeping services.