Possibly The Eternity Brigade by Stephen Goldin.
Hundreds of human bodies have been placed in coffins in a military warehouse. But they are not dead, merely frozen in a cryogenic process meant to preserve an army of men to be restored to life if ever they are needed. The Earth they arise to inhabit is a world completely different from any they have known or imagined. Their only task is to fight and kill in the wars that plague the planet. They are not treated as men, but as fighting machines to be endlessly duplicated and used up. By having had their genetic patterns programmed into a computer, they are doomed to live over and over again, as part of an army that will not die and cannot escape. Yet one man is determined to break the pattern and free himself, truly believing that there must be a way out...of eternity.
The soldier is Jerry Hawker.
The book didn't make that much impact on me and I don't remember that much about it, but it broadly matches your description. The soldiers are continuously resurrected to fight again, and the book does end with Hawker destroying the computer that holds all their templates. The story ends:
There was something hard and smooth in his left hand. The grenade.
He still held the grenade. He could not turn his head to see it, but he had
handled so many grenades that his fingers knew its surface intimately. Set
it, he ordered his hand, and the fingers moved slowly to obey. First he
turned one small dial, then another. A timer fuse. Fifteen seconds. With
the last gram of strength in his body, he pushed the grenade away from
him along the floor, toward the computer, knowing there were millions of
things that could still go wrong. Maybe he hadn't set the grenade right.
Maybe there was a third record of him somewhere. Maybe…
Jerry Hawker did not live to see the explosion, nor to realize that it
produced more than satisfactory results. But that, in and of itself, was a
victory.
At long last, and forever, Hawker knew peace.