The writ of habeas corpus may be granted by the district court, upon petition by or on behalf of any person restrained of his liberty.