A train strike that could have brought Sydney to a standstill has been avoided after the government agreed to run 24-hour services.