Setting custom users and groups

Björn Raupach raupach at me.com
Tue Jul 28 05:28:19 PDT 2015


Dear group,

I am new to Portfile development and have a problem with permissions for users and groups. At the moment I am trying to create a Portfile for Apache Tomcat 8. I would like to run Tomcat as non-root with a user `tomcat` and group `tomcat`. I am a bit lost.

set catalina_home   ${destroot}${prefix}/share/java/${name}
set tomcat_user      tomcat
set tomcat_group    tomcat
add_users ${tomcat_user} group=${tomcat_group}

I saw these lines in some other ports, for example couchdb, and figured that is the way to go even though I don’t find the macro add_users anywhere in the documentation. 

My destroot-phase currently looks like this:

destroot {
    xinstall -m 755 -g ${tomcat_group} -d ${catalina_home}

    file copy \
        ${worksrcpath}/LICENSE \
        ${worksrcpath}/NOTICE \
        ${worksrcpath}/RELEASE-NOTES \
        ${worksrcpath}/RUNNING.txt \
        ${worksrcpath}/bin \
        ${worksrcpath}/conf \
        ${worksrcpath}/lib \
        ${worksrcpath}/logs \
        ${worksrcpath}/temp \
        ${worksrcpath}/webapps \
        ${worksrcpath}/work \
        ${catalina_home}

    xinstall -m 644 ${filespath}/setenv.sh ${catalina_home}/bin/setenv.sh.default

    # replace @PREFIX@ to ${prefix}
    reinplace "s|@PREFIX@|${prefix}|g" ${catalina_home}/bin/setenv.sh.default
    # replace @NAME@ to ${name}
    reinplace "s|@NAME@|${name}|g" ${catalina_home}/bin/setenv.sh.default
}

However `/opt/local/share/java/tomcat8` has the ownership `root:admin` and not `root:tomcat`.

What am I missing?

Any help would be appreciated. Thanks!

kind regards,
Björn


More information about the macports-dev mailing list