| example bizbox.conf file, used by the script | |
| DOMAIN_IP=192.168.0.13 | |
| MY_HOSTNAME=smartos.allenlan.net | |
| BIZBOX_DEFINED="true" | |
| the script (the AD join stuff is near the bottom) | |
| #!/bin/bash | |
| # | |
| # Bizbox setup service - the "bizbox-setup" SMF service runs this once on boot | |
| # | |
| # Configures: | |
| # - auto-backup (crontab, syslog) | |
| # - iscsi volumes | |
| # - joins a domain | |
| # | |
| # Modification history: | |
| # 20130417: recover the AD join state by importing smb/server service info | |
| set -o xtrace | |
| . /lib/svc/share/smf_include.sh | |
| cd / | |
| #PATH=/usr/sbin:/usr/bin; export PATH | |
| # | |
| # get variables from /opt/bizbox/conf/bizbox.conf | |
| # | |
| CONFFILE=/opt/bizbox/conf/bizbox.conf | |
| if [ -z "$BIZBOX_DEFINED" -a -x $CONFFILE ]; then | |
| . $CONFFILE | |
| fi | |
| case "$1" in | |
| 'start') | |
| # | |
| # append a logging entry to /etc/syslog.conf | |
| # | |
| touch /var/log/bizbox.log | |
| echo -e "news.debug\t/var/log/bizbox.log" >> /etc/syslog.conf | |
| # | |
| # append a crontab line to run the backup script every hour | |
| # | |
| echo -e "0 * * * * /bin/bash /opt/bizbox/bin/bxbackup.sh" > /var/spool/cron/crontabs/root | |
| /usr/sbin/svcadm restart cron | |
| # | |
| # move ssh private key file into /root/.ssh/ | |
| # | |
| if [ -f /opt/bizbox/conf/id_rsa ]; then | |
| [ -d /root/.ssh ] || mkdir /root/.ssh | |
| chmod 700 /root/.ssh | |
| cp /opt/bizbox/conf/id_rsa /root/.ssh/ | |
| chmod 600 /root/.ssh/id_rsa | |
| cp /opt/bizbox/conf/id_rsa.pub /root/.ssh/ | |
| chmod 644 /root/.ssh/id_rsa.pub | |
| fi | |
| # | |
| # set up any iscsi volumes that have been created in zones/iscsi | |
| # | |
| /usr/sbin/svcadm enable stmf | |
| /usr/sbin/svcadm enable -r svc:/network/iscsi/target:default | |
| MYIP=$(ifconfig | grep inet | grep broadcast | awk '{print $2}') | |
| itadm create-tpg ISCSI-GROUP $MYIP | |
| for VOLNAME in $(zfs list -Hr -t volume zones/iscsi | awk '{print $1}' | awk -F/ '{print $3}') | |
| do | |
| # capture the output of this command | |
| GUID=$(sbdadm create-lu /dev/zvol/rdsk/zones/iscsi/$VOLNAME | grep $VOLNAME | awk '{print $1}') | |
| /usr/sbin/stmfadm add-view $GUID | |
| /usr/sbin/itadm create-target -n iqn.2010-08.org.illumos:$VOLNAME -t ISCSI-GROUP | |
| done | |
| # | |
| # set hostname | |
| # | |
| if [ -n "$MY_HOSTNAME" ]; then | |
| hostname $MY_HOSTNAME | |
| echo $MY_HOSTNAME > /etc/nodename | |
| fi | |
| # | |
| # recover the AD join state by importing smb/server service info | |
| # | |
| # how to create the service info export file: | |
| # 1. perform the commands below: copies, sharectl, but not svcadm/svccfg | |
| # 2. svcadm enable -r smb/server | |
| # 3. smbadm join | |
| # 4. svccfg export -a smb/server > /opt/bizbox/conf/smb-server.exp | |
| SVCEXPFILE=/opt/bizbox/conf/smb-server.exp | |
| if [ ! -f $SVCEXPFILE -o -z "$DOMAIN_IP" ]; then | |
| logger -p news.info "Error: cannot rejoin domain, config files not defined" | |
| else | |
| # | |
| # wait up to 5 minutes for AD to come up | |
| # test for it by trying to connect to ports 139 & 389 | |
| # | |
| ADS_ALIVE=0 | |
| JD_STIME=$(date +%s) | |
| let JD_ETIME=300+$JD_STIME | |
| while [ 1 ]; do | |
| nc -vz -w 5 $DOMAIN_IP 139 >/dev/null 2>&1 | |
| if [ "$?" = "0" ]; then | |
| nc -vz -w 5 $DOMAIN_IP 389 >/dev/null 2>&1 | |
| if [ "$?" = "0" ]; then | |
| ADS_ALIVE=1 | |
| break | |
| fi | |
| fi | |
| if [ $(date +%s) -gt $JD_ETIME ]; then | |
| logger -p news.info "bizbox setup script - AD VM not responding, timeout elapsed" | |
| break | |
| fi | |
| sleep 15 | |
| done | |
| if [ "$ADS_ALIVE" = "1" ]; then | |
| [ -f /opt/bizbox/conf/hosts ] && cp /opt/bizbox/conf/hosts /etc/ | |
| [ -f /opt/bizbox/conf/resolv.conf ] && cp /opt/bizbox/conf/resolv.conf /etc/ | |
| [ -f /opt/bizbox/conf/krb5.conf ] && cp /opt/bizbox/conf/krb5.conf /etc/krb5/ | |
| [ -f /etc/nsswitch.dns ] && cp /etc/nsswitch.dns /etc/nsswitch.conf | |
| /usr/sbin/sharectl set -p pdc=$DOMAIN_IP -p ads_site=$DOMAIN_IP smb | |
| /usr/sbin/svcadm disable smb/server | |
| /usr/sbin/svccfg import $SVCEXPFILE | |
| fi | |
| fi | |
| ;; | |
| 'stop') | |
| ;; | |
| *) | |
| echo "Usage: $0 start" | |
| exit $SMF_EXIT_ERR_FATAL | |
| ;; | |
| esac | |
| exit $SMF_EXIT_OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment