This paper presents an online trajectory optimization algorithm for launch vehicles based on convex programming to ensure flight safety in case of power system fault. Due to high complexity of the power system, the engine may break down during the flight, causing significant decrease of thrust or energy. In this case, the nominal trajectory will be infeasible as the dynamical model and energy state is different from the normal status, thus the online trajectory optimization and re-planning are considered. For different kinds of engine failures, different terminal orbital constraints are proposed. When the mass flow rate of fuel decreases, the energy loss is little but the dynamical model changes obviously, so the location of the injection point cannot be guaranteed. In this case, the terminal orbital elements are constrained except the true anomaly, so that the payload of launch vehicles can still settle into the nominal orbit, and the true anomaly is optimized for minimum fuel consumption. As for the energy-loss failure, the strategy to change the target orbit is proposed considering the requirement of launch mission and subsequent orbit transfer insertion. The terminal constraints are proposed analytically in this paper. In order to solve the nonconvex trajectory optimization problem accurately and rapidly, the optimization problem is transformed into convex optimization problems by various convexification techniques, including the lossless convexification and successive convexification. Finally, the high efficiency and accuracy of the proposed algorithm is verified by numerical experiments. The algorithm proposed in this paper has potential applications in onboard trajectory optimization and re-planning of launch vehicles in case of power system fault to ensure the accomplishment of the launch mission.