$ svn diff
Index: Portfile
===================================================================
--- Portfile	(revision 152059)
+++ Portfile	(working copy)
@@ -9,7 +9,7 @@
 set version_branch  [join [lrange [split ${version} .] 0 1] .]
 # Please set revision_client and revision_server to 0 if you bump version.
 set revision_client 0
-set revision_server 0
+set revision_server 4
 categories          databases
 platforms           darwin
 license             GPL-2
@@ -202,13 +202,30 @@
     revision            ${revision_server}
     license             BSD
     description         Run ${name_mysql} as server
-    long_description    ${description}
+    long_description    MariaDB is one of the most popular database servers in the world. \
+        It’s made by the original developers of MySQL and is a fast, scalable and robust \
+        relational database providing an SQL interface for accessing structured data.
 
     supported_archs     noarch
     distfiles
+    set plistlabel      org.macports.mariadb-server
+    set plistfile       ${plistlabel}.plist
+    set plistdir        ${prefix}/etc/LaunchDaemons/${plistlabel}
 
     depends_run         port:${name_mysql}
 
+    pre-patch {
+        file mkdir ${worksrcpath}/macports
+        copy ${filespath}/${plistfile} ${worksrcpath}/macports/
+    }
+
+    post-patch {
+        reinplace -locale C "s|@NAME@|${name_mysql}|g" \
+            ${worksrcpath}/macports/${plistfile}
+        reinplace -locale C "s|@PREFIX@|${prefix}|g" \
+            ${worksrcpath}/macports/${plistfile}
+    }
+
     if {"darwin" eq ${os.platform} && ${os.major} > 8} {
         set mysqluser       _mysql
     } else {
@@ -216,9 +233,6 @@
     }
     add_users ${mysqluser} group=${mysqluser} realname=MySQL\ Server
 
-    startupitem.create      yes
-    startupitem.executable  ${prefix}/lib/${name_mysql}/bin/mysqld --user=${mysqluser}
-
     use_configure       no
 
     build {}
@@ -235,6 +249,39 @@
             ${destroot}${prefix}/var/db/${name_mysql} \
             ${destroot}${prefix}/var/log/${name_mysql} \
             ${destroot}${prefix}/var/run/${name_mysql}
+        xinstall -d -m 0755 ${destroot}${plistdir}
+        xinstall ${worksrcpath}/macports/${plistfile} ${destroot}${plistdir}
+    }
+
+    post-activate {
+        # delete leftover file, if any
+        if [file exists /Library/LaunchDaemons/${plistfile}] {
+            file delete -force /Library/LaunchDaemons/${plistfile}
+        }
+        if {${startupitem.install} eq "yes"} {
+            ln -s ${plistdir}/${plistfile} /Library/LaunchDaemons
+        } else {
+            notes-append "
+Installation of the startup item was prohibited due to a setting."
+        }
+    }
+
+    pre-deactivate {
+         file delete -force /Library/LaunchDaemons/${plistfile}
+    }
+
+    pre-pkg {
+        file copy ${filespath}/preinstall \
+            ${filespath}/postinstall \
+            ${package.scripts}/
+        reinplace -locale C "s|@NAME@|${name_mysql}|g" \
+            ${package.scripts}/preinstall \
+            ${package.scripts}/postinstall
+        reinplace -locale C "s|@PREFIX@|${prefix}|g" \
+            ${package.scripts}/preinstall \
+            ${package.scripts}/postinstall
+        file attributes ${package.scripts}/preinstall -permissions 0755
+        file attributes ${package.scripts}/postinstall -permissions 0755
     }
 
     notes "
Index: files/org.macports.mariadb-server.plist
===================================================================
--- files/org.macports.mariadb-server.plist	(nonexistent)
+++ files/org.macports.mariadb-server.plist	(working copy)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+    <key>Label</key>             <string>org.macports.@NAME@-server</string>
+    <key>ProcessType</key>       <string>Interactive</string>
+    <key>Disabled</key>          <false/>
+    <key>RunAtLoad</key>         <true/>
+    <key>KeepAlive</key>         <true/>
+    <key>SessionCreate</key>     <true/>
+    <key>LaunchOnlyOnce</key>    <false/>
+    <key>UserName</key>          <string>_mysql</string>
+    <key>GroupName</key>         <string>_mysql</string>
+    <key>ExitTimeOut</key>       <integer>600</integer>
+    <key>ProgramArguments</key>
+        <array>
+            <string>@PREFIX@/lib/@NAME@/bin/mysqld</string>
+            <string>--datadir=@PREFIX@/var/db/@NAME@</string>
+            <string>--plugin-dir=@PREFIX@/lib/@NAME@/plugin</string>
+            <string>--log-error=@PREFIX@/var/log/@NAME@/mysqld.local.err</string>
+            <string>--pid-file=@PREFIX@/var/run/@NAME@/mysqld.local.pid</string>
+        </array>
+</dict>
+</plist>
Index: files/postinstall
===================================================================
--- files/postinstall	(nonexistent)
+++ files/postinstall	(working copy)
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+# MariaDB installer support, postinstall script
+# runs as root after installer successfully copies payload to destination
+# Adapted from https://github.com/MariaDB/server/blob/5.5/support-files/MacOSX/postflight.sh
+
+# Have experienced cases where installed directories/files have different 
+# ownership or permissions than what was fed to PackageMaker.
+# Just use blunt force to set the required permissions
+
+chmod 644 @PREFIX@/etc/LaunchDaemons/org.macports.@NAME@-server/org.macports.@NAME@-server.plist || exit 1
+if [ -f /Library/LaunchDaemons/org.macports.@NAME@-server.plist ] ; then
+   rm /Library/LaunchDaemons/org.macports.@NAME@-server.plist
+fi
+ln -s @PREFIX@/etc/LaunchDaemons/org.macports.@NAME@-server/org.macports.@NAME@-server.plist \
+    /Library/LaunchDaemons/org.macports.@NAME@-server.plist || exit 1
+
+chown _mysql:_mysql @PREFIX@/var/run/@NAME@ || exit 1
+chown _mysql:admin  @PREFIX@/var/db/@NAME@ || exit 1
+chown _mysql:_mysql @PREFIX@/var/log/@NAME@ || exit 1
+
+
+# standard mysql initialization
+if [ ! -f @PREFIX@/var/db/@NAME@/mysql/db.frm ] ; then
+    @PREFIX@/lib/@NAME@/bin/mysql_install_db --user=_mysql --datadir=@PREFIX@/var/db/@NAME@
+fi
+
+# we should be able to trust that preinstall did this, but...
+# just in case still loaded, unload
+if /bin/launchctl list "org.macports.@NAME@-server" &> /dev/null; then
+    /bin/launchctl unload "/Library/LaunchDaemons/org.macports.@NAME@-server.plist"
+fi
+
+# my.cnf may not be in place yet, but the server will run anyway
+/bin/launchctl load -w /Library/LaunchDaemons/org.macports.@NAME@-server.plist 

Property changes on: files/postinstall
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: files/preinstall
===================================================================
--- files/preinstall	(nonexistent)
+++ files/preinstall	(working copy)
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# MariaDB installer support, preinstall script
+# runs as root just after user clicks "Install"
+
+# if daemon loaded, unload
+if /bin/launchctl list "org.macports.@NAME@-server" &> /dev/null; then
+    /bin/launchctl unload "/Library/LaunchDaemons/org.macports.@NAME@-server.plist"
+fi
