(Updates refinery toll, adds details on Gaddafi message, China recognition)
RAS LANUF, Libya, Sept 12 (Reuters) - Muammar Gaddafi loyalists killed 17 guards outside an oil refinery on Monday in an apparent attempt to disrupt a drive by Libya's new rulers to seize the ousted ruler's last bastions and revive the oil-based economy.
A Syrian-based television station that has broadcast messages from Gaddafi in the past said he was still in Libya, but it was unable to air a televised appearance for security reasons.
"It was meant to show the leader among his fighters and people, leading the struggle from Libyan lands, and not from Venezuela or Niger or anywhere else," Mishan Jabouri, owner of the Arrai channel, told viewers.
He read out a text quoting Gaddafi as saying: "We cannot give up Libya to colonisation one more time ... There is nothing more to do except fight until victory."
Libya's new ruling National Transitional Council (NTC) says that as long as Gaddafi remains on the run he is capable of attracting followers to a dangerous insurgency -- of the kind which the refinery attack might prefigure.
Gaddafi fighters in more than a dozen vehicles drove to the refinery, 20 km (13 miles) from the coastal town of Ras Lanuf, and fired on a checkpoint outside, witnesses said.
The refinery, which is not fully operational, was undamaged, but the entrance, guarded by a blackened NTC tank, was littered with used hand grenades.
A doctor at Ras Lanuf hospital said the death toll had risen to 17 after one of two wounded people died.
"We heard firing and shelling at around 9 in the morning from Gaddafi loyalists," refinery worker Ramadan Abdel Qader, who had been shot in the foot, told Reuters.
The assault occurred only hours after the NTC announced it had resumed some oil production, which had been all but halted since anti-Gaddafi protests turned into civil war in March.
STRUGGLE FOR CONTROL
The NTC is struggling to assert its control over Libya and capture a handful of stubbornly-defended Gaddafi-held towns.
NTC forces, which seized Tripoli on Aug. 23, said they were meeting fierce resistance on the fourth day of fighting for the desert town of Bani Walid, 150 km (95 miles) southeast of the capital, and were edging towards Sirte, Gaddafi's birthplace.
Libya's economy depends almost entirely on oil and gas. Interim Prime Minister Mahmoud Jibril said on Sunday some oil production had resumed, but would not say where or how much.
Libya holds Africa's largest crude oil reserves and sold about 85 percent of its exports to Europe under Gaddafi. Western oil firms, including Italy's Eni and Austria's OMV , are keen to restore production.
Eni's chief executive told Reuters his priority was to restart gas exports via a pipeline from Libya to Italy by October or November. Resuming oil output was less urgent.
"We are by far the biggest player in Libya, both in oil and in gas, so I came here with the idea of 'back to normal'," Paolo Scaroni said during a visit to Tripoli.
China, which obtained three percent of its oil imports from Libya last year, recognised the NTC as the country's "ruling authority", ending weeks of uncertainty about when Beijing would formally embrace those who overthrew Gaddafi.
In Bani Walid, fleeing residents reported intense street fighting while NATO warplanes could be heard overhead.
Families trapped there for weeks escaped after Gaddafi forces abandoned some checkpoints on the outskirts. Dozens of cars packed with civilians streamed out of the area.
"We are leaving because of the rockets. They are falling near civilian homes," said one resident, Ali Hussain.
The NTC has sent extra units to Bani Walid, but some fighters said this only worsened tribal tensions between fighters from other areas and those from the town.
NTC spokesman Ahmed Bani said the plan for Bani Walid for now was to wait, accusing Gaddafi forces of using civilians as human shields by putting missile launchers on their roofs, so that NTC forces or NATO planes could not strike.
NATO has denied coordinating its air raids with NTC forces but has acknowledged its planes have been bombing targets around Bani Walid, Sirte and other Gaddafi redoubts.
Secretary General Anders Fogh Rasmussen said NATO would pursue operations in Libya while a threat to civilians persists, whether or not Gaddafi was found, but did not expect to play a big role there once the conflict was over.
As pressure builds on Gaddafi's last strongholds, some of his top officials and family members have fled abroad. His son Saadi arrived in neighbouring Niger on Sunday after crossing the remote Sahara desert frontier. Two other sons and Gaddafi's only biological daughter have fled to Algeria. One son is reported to have died in the war and three are still at large.
The NTC has said it will send a delegation to Niger to seek the return of anyone wanted for crimes.
Niger, like Algeria, has cited humanitarian reasons for accepting fugitives from the former government, but has promised to respect its commitments to the International Criminal Court, which wants to try Gaddafi, son Saif al-Islam and intelligence chief Abdullah al-Senussi for war crimes.
In Tripoli, NTC fighters revealed they had captured Gaddafi's foreign spy chief, Bouzaid Dorda.
Reuters reporters saw Dorda, a former prime minister who ran Gaddafi's external spy service, held by a score of fighters in a house in the capital's Zenata district on Sunday.
A lanky figure in a safari jacket, Dorda was sitting on a sofa with an armed guard beside him. When a fighter asserted that he had killed people, he replied defiantly: "Prove it." (Additional reporting by Maria Golovnina north of Bani Walid, Emma Farge in Benghazi, William Maclean, Hisham el-Dani, Alexander Dziadosz and Mohammed Abbas in Tripoli, Mark John and Bate Felix in Niamey, Barry Malone and Sylvia Westall in Tunis, Keith Weir in London and Isabel Coles in Dubai; Writing by Alistair Lyon)