What version of Berkeley DB are you using?
I don't see any evidence in your sample code that you are following the procedure for a primordial startup. The very first time that you start your first replication manager site, you need to configure it as DB_GROUP_CREATOR as well as DB_LOCAL_SITE. You need to do this to create the initial version of our internal group membership database. Later startups for this site do not need to configure DB_GROUP_CREATOR, but if it is specified it is ignored. I suspect that your later restarts are returning DB_REP_UNAVAIL because they are looking for our internal group membership database and not finding it.
In your case, you should start again from scratch with an empty environment directory. Add a second call to dbsite->set_config() to also configure DB_GROUP_CREATOR before you call db_env->repmgr_start(). See if this changes the behavior when you later try to restart your master site.
You can find more information about the primordial start procedure in the Berkeley DB Programmer's Reference Guide section "Managing Replication Manager group membership".