Skip to content

Instantly share code, notes, and snippets.

@bahamat
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bahamat/b48d1c8424c591487ac8 to your computer and use it in GitHub Desktop.
Save bahamat/b48d1c8424c591487ac8 to your computer and use it in GitHub Desktop.
SMF Manifest and shell script for SmartOS to register common, active DNS-SD services.
#!/bin/bash
# dnssd-register.sh -- Register common services for SmartOS
#
# This is really only useful for people who run SmartOS on a LAN segment
# with workstations. E.g., your house.
#
# This script scans for common locally listening services and registers
# them with mDNS/DNS-SD/Bonjour.
#
# Copyright 2014 Brian Bennett
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
typeset -a port
kill_children() {
for child in ${CHILDREN}
do
kill $child
done
}
trap kill_children TERM
port[22]="_ssh"
port[21]="_ftp"
port[445]="_smb"
port[548]="_afpovertcp"
port[631]="_ipp"
NETSTAT=$(netstat -na -f inet -f inet6)
for key in ${!port[@]}
do
RE=".${key}[^[:digit:]].*LISTEN"
if [[ "$NETSTAT" =~ $RE ]]
then
/usr/bin/dns-sd -R ${HOSTNAME} ${port[${key}]}._tcp local ${key} &
CHILDREN="$! $CHILDREN"
fi
done
wait $CHILDREN
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
Created by Manifold
--><service_bundle type="manifest" name="dnssd-register">
<service name="site/dnssd-register" type="service" version="1">
<create_default_instance enabled="true"/>
<single_instance/>
<dependency name="network" grouping="require_all" restart_on="error" type="service">
<service_fmri value="svc:/milestone/network:default"/>
</dependency>
<dependency name="filesystem" grouping="require_all" restart_on="error" type="service">
<service_fmri value="svc:/system/filesystem/local"/>
</dependency>
<method_context>
<method_credential user="nobody" group="nobody"/>
</method_context>
<exec_method type="method" name="start" exec="/opt/custom/bin/dnssd-register.sh" timeout_seconds="60"/>
<exec_method type="method" name="stop" exec=":kill" timeout_seconds="60"/>
<property_group name="startd" type="framework">
<propval name="duration" type="astring" value="child"/>
<propval name="ignore_error" type="astring" value="core,signal"/>
</property_group>
<property_group name="application" type="application">
</property_group>
<stability value="Evolving"/>
<template>
<common_name>
<loctext xml:lang="C">
DNS-SD Registration
</loctext>
</common_name>
</template>
</service>
</service_bundle>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment