On a recent afternoon, the lobby of one of Mogadishu's most popular hotels was nearly empty, a stark contrast to the days when one could hardly find a seat.

"We have lost over 60 percent of our customers in the past three months because of the attacks on hotels," said manager Ali Hassan. Elsewhere in town, Mohamed Timir smoked a shisha pipe at his apartment, missing his favorite hangout but saying, "I would rather stay at home."

War-weary Somalis are trying to relax and rebuild their country after decades of violence, but the homegrown Islamic extremists al-Shabab keep striking at the heart of its seaside capital, killing scores of people so far this year. On Tuesday, a suicide bomber detonated an explosives-laden truck near the gate of the presidential palace, killing at least 12 people.

Now the 22,000-strong African Union force protecting the country faces funding cuts and troop shortages, which experts say could further destabilize this Horn of Africa nation.

Somalia largely relies on the African peacekeeping force to maintain security, especially as the country prepares for a presidential election in October, a significant step toward normal life.

In another sign of confidence, Mogadishu next month will host a summit for heads of state with the regional bloc Inter-Governmental Authority on Development, the first such gathering here in over two decades.

Optimism can be found around the city, even as attacks continue. The Mogadishu Mall, billed as the city's first international-standard shopping center, is under construction. The second annual Mogadishu Book Fair just ended. Somalis return from overseas with investment in mind. Flowers were even planted along some streets.

"The city has made impressive progress, unlike the usual narratives of bombings and bloody scenes," said one returnee from the United States, 40-year-old Deqa Ali, who fled Mogadishu with her family in 1993. She spoke after stepping out of a public park, Peace Garden, with her three children.

Everyone in the capital craves security. But while the peacekeeping commanders have announced plans to mount new operations against al-Shabab, which is allied to al-Qaida, the force has been losing the support of its partners. Its largest donor, the European Union, cut its funding by 20 percent earlier this year, leaving the African countries that contribute to the multinational force scrambling to come up with their own money.

In frustration, Uganda, the largest contributor of troops, announced it would pull its more than 6,000 troops from Somalia by the end of 2017.

Then the African Union announced it plans to withdraw the force completely by the end of 2020, saying security responsibilities will be transferred to Somalia's military gradually, starting in 2018.

"It seems that there is a fatigue by the international community, especially the EU," said Abukar Sanei, the executive director for the Center for Policy Analysis and Research, a Mogadishu-based think tank. "One of the reasons that the fatigue can be attributed is that honestly, AMISOM (the African Union peacekeeping force) is not winning the war against al-Shabaab."

While the insurgents have been ousted from most of Somalia's cities, they continue to carry out bombings and suicide attacks, most notably in the capital.

Late last month, two al-Shabab suicide bombers detonated explosives-laden cars outside the office of the U.N.'s mine-clearing agency and a Somali army checkpoint near the African Union's main base in Mogadishu, killing 13 people.

Other attacks have targeted hotels. In late June, extremist gunmen stormed the Nasa-Hablod hotel, killing at least 14 people. Two weeks before that, extremist gunmen killed 15, including two members of parliament, at the Ambassador hotel.

Mogadishu residents say they worry that al-Shabab is trying to disrupt the upcoming elections.

"Unless things are changed on security perspective, I think al-Shabab will do everything to kill many and shatter the fragile peace we have now," said Yusuf Ali, a university lecturer in Mogadishu.

The Islamist rebels are trying to impose an austere Shariah law. They have targeted the African Union force, killing at least 180 Kenyan soldiers in an attack on an army base in southwestern Somalia in January.

Many residents doubt that Somalia will be able to assume its own security by 2020 when the peacekeeping force will be pulled out. Somalia's army as it stands now has no capability to respond to an al-Shabab resurgence in the future, warned Ahmed Warsame, a retired Somali military general and a former legislator.

"A long way to go," said Warsame, of the need for Somali troops to take over protecting the country's stability. "And in practice, little progress has been made to enable that transition."