Like many summer havens, this town on the tip of Cape Cod is threatened by a shrinking, graying population and scarcities of housing and year-round jobs.