Skip to content

Instantly share code, notes, and snippets.

@poige
Forked from sjorge/persist-syscfg
Created July 6, 2017 18:01
Show Gist options
  • Save poige/a65a1e4c67ccdf4a333fc96f76b182af to your computer and use it in GitHub Desktop.
Save poige/a65a1e4c67ccdf4a333fc96f76b182af to your computer and use it in GitHub Desktop.
SmartOS File Server
#!/usr/bin/bash
# Originally based on http://wiki.smartos.org/display/DOC/Allowing+user+CRUD+in+the+global+zone
# Author: hugo@freenode
enable_stmf=1
enable_smb=1
enable_nfs=1
save_us=( /etc/passwd /etc/shadow /etc/group /etc/ouser_attr /etc/user_attr \
/etc/security/policy.conf /etc/security/auth_attr /etc/security/exec_attr \
/etc/security/prof_attr /etc/pam.conf /var/smb/smbpasswd /var/smb/osmbpasswd /var/smb/smbgroup.db )
ukeystor="/usbkey/cn-persist"
# this script needs rsync
if [ ! -f /usr/bin/rsync ]; then
echo please install rsync
exit 1
fi
case "$1" in
'start')
if [[ -n $(/bin/bootparams | grep '^smartos=true') ]]; then
# file magic
for file in ${save_us[*]}
do
ukf=${ukeystor}${file}
if [[ -z $(/usr/sbin/mount -p | grep $file) ]]; then
if [[ $ukf -ot $file ]]; then
rsync -Rrtpogu $file $ukeystor
echo "sys->stor: $file"
else
rsync -rtpog $ukf $file
echo "stor->sys: $file"
fi
touch $file $ukf
mount -F lofs $ukf $file
fi
done
mkdir -p ${ukeystor}/svc/
[ -e /tmp/nfssrv.lock ] && svccfg export -a nfs/server > ${ukeystor}/svc/nfssrv.prop
[ -e ${ukeystor}/svc/nfssrv.prop ] && svccfg import ${ukeystor}/svc/nfssrv.prop
touch /tmp/nfssrv.lock
[ -e /tmp/smbsrv.lock ] && svccfg export -a smb/server > ${ukeystor}/svc/smbsrv.prop
[ -e ${ukeystor}/svc/smbsrv.prop ] && svccfg import ${ukeystor}/svc/smbsrv.prop
touch /tmp/smbsrv.lock
[ -e /tmp/stmf.lock ] && svccfg export -a stmf > ${ukeystor}/svc/stmf.prop
[ -e ${ukeystor}/svc/stmf.prop ] && svccfg import ${ukeystor}/svc/stmf.prop
touch /tmp/stmf.lock
# enable services
if [ ${enable_stmf} -gt 0 ]; then
svcadm enable system/stmf
svcadm enable iscsi/target
fi
if [ ${enable_smb} -gt 0 ]; then
svcadm enable system/idmap
svcadm enable smb/client
svcadm enable smb/server
fi
if [ ${enable_nfs} -gt 0 ]; then
svcadm enable nfs/server
fi
fi
;;
'stop')
for file in ${save_us[*]}
do
if [[ -n $(/usr/sbin/mount -p | grep $file) ]]; then
umount $file && touch $file
fi
done
;;
esac
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='export'>
<service name='site/persist-syscfg' type='service' version='0'>
<create_default_instance enabled='true'/>
<single_instance/>
<dependency name='filesystem' grouping='require_all' restart_on='error' type='service'>
<service_fmri value='svc:/system/filesystem/local'/>
</dependency>
<dependent name='nsc' grouping='require_all' restart_on='refresh'>
<service_fmri value='svc:/system/name-service-cache' />
</dependent>
<method_context/>
<exec_method name='start' type='method' exec='/opt/custom/smf/bin/persist-syscfg start' timeout_seconds='60'/>
<exec_method name='stop' type='method' exec='/opt/custom/smf/bin/persist-syscfg stop' timeout_seconds='60'/>
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient'/>
<propval name='ignore_error' type='astring' value='core,signal'/>
</property_group>
<property_group name='application' type='application'/>
<stability value='Evolving'/>
<template>
<common_name>
<loctext xml:lang='C'>Apply configuration from /usbkey, making it persistent</loctext>
</common_name>
</template>
</service>
</service_bundle>
@poige
Copy link
Author

poige commented Jul 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment