  Recent experiments have implemented resetting by means of an external trap,
whereby a system relaxes to the minimum of the trap and is reset in a finite
time. In this work, we set up and analyze the thermodynamics of such a
protocol. We present a general framework, even valid for non-Poissonian
resetting, that captures the thermodynamic work required to maintain a
resetting process up to a given observation time, and exactly calculate the
moment generating function of this work. Our framework is valid for a wide
range of systems, the only assumption being of relaxation to equilibrium in the
resetting trap. Examples and extensions are considered, including the validity
of fluctuation theorems. In the case of Brownian motion, we investigate optimal
resetting schemes that minimize work and its fluctuations, the mean work for
arbitrary switching protocols and comparisons to earlier-studied resetting
schemes. Numerical simulations are performed to validate our findings.

Statistical Mechanics;Soft Condensed Matter