Arthur Schopenhauer said this quote

If you want a safe compass to guide you through life, and to banish all doubt as to the right way of looking at it, you cannot do better than accustom yourself to regard this world as a penitentiary... • If you accustom yourself to this view of life you will regulate your expectations accordingly, and cease to look upon all its disagreeable incidents, great and small, its sufferings, its worries, its misery, as anything unusual or irregular; nay, you will find that everything is as it should be, in a world where each of us pays the penalty of existence in his own peculiar way.