Action principle for relativistic magnetohydrodynamics