Russian President Dmitry Medvedev has signed a ceasefire agreement ending hostilities with Georgia over South Ossetia.