As longtime workers retire and younger applicants look elsewhere, towns are struggling to staff the jobs that keep them functioning.