Skip to content

Commit

Permalink
Merge pull request samba-team#6 from dl566/fix-issue2-configuration-sync
Browse files Browse the repository at this point in the history
samba-issue5-v1:  add feature of configuration files sync based on ctdb fix issue samba-team#5
  • Loading branch information
dl566 committed Dec 1, 2016
2 parents a6a1f95 + cbac715 commit 8c7d8c9
Show file tree
Hide file tree
Showing 16 changed files with 593 additions and 4 deletions.
1 change: 0 additions & 1 deletion ctdb/.gitignore
Expand Up @@ -5,7 +5,6 @@ config.status
configure
ctdb.pc
publish*.sh
push*.sh
web/packages
TAGS
tags
Expand Down
28 changes: 28 additions & 0 deletions ctdb/client/ctdb_client.c
Expand Up @@ -4658,6 +4658,34 @@ int ctdb_ctrl_enablescript(struct ctdb_context *ctdb, struct timeval timeout, ui

return 0;
}
/*sync configuration*/
int ctdb_ctrl_syncconfig(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, const char *script)
{
int ret;
TDB_DATA data;
int32_t res;
char *ctdb_base="/etc/ctdb";
char cmdarray[256] = {'\0'};
sprintf(cmdarray, "%s/pushconfig %s", ctdb_base, script);
ret = system(cmdarray);
if(ret != 0)
{
DEBUG(DEBUG_ERR, (__location__ "pushconfig into registry.tdb failed. ret: %d\n", ret));
return -1;
}
data.dsize = strlen(script) + 1;
data.dptr = discard_const(script);

ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_SYNC_CONFIG, 0, data,
NULL, NULL, &res, &timeout, NULL);
if (ret != 0 || res != 0) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_control for syncconfig failed\n"));
return -1;
}

return 0;
}

/* disable an eventscript
*/
Expand Down
32 changes: 32 additions & 0 deletions ctdb/config/notify.d.syncconfig
@@ -0,0 +1,32 @@
#!/bin/sh
. /etc/ctdb/pull_config.sh

update_config()
{
if [ "x$1" == "xall" ] ; then
pull_smb
pull_dns
pull_nfs
fi

if [ "x$1" == "xsmb" ] ; then
pull_smb
fi

if [ "x$1" == "xdns" ] ; then
pull_dns
fi

if [ "x$1" == "xnfs" ] ; then
pull_nfs
fi
}

case "$1" in
sync)
update_config $2
;;
healthy)
update_config $2
;;
esac
12 changes: 12 additions & 0 deletions ctdb/config/notify.sh
Expand Up @@ -11,6 +11,13 @@ nd="${d}/notify.d"

ok=true

echo "begin to execute notify.sh"

if [ ! -f "/var/run/ctdb/synclock" ] ; then
touch /var/run/ctdb/synclock > /dev/null 2>&1

fi

for i in "${nd}/"* ; do
# Don't run files matching basename
case "${i##*/}" in
Expand All @@ -21,6 +28,11 @@ for i in "${nd}/"* ; do
[ -x "$i" ] || continue

# Flag failures
if [ "x$2" != "x" ] ; then
flock -x -w 5 /var/run/ctdb/synclock -c "\"$i\" \"$1\" \"$2\"" || ok=false
continue
fi

"$i" "$1" || ok=false
done

Expand Down
222 changes: 222 additions & 0 deletions ctdb/config/pull_config.sh
@@ -0,0 +1,222 @@
#!/bin/sh
tmp_dir="/var/run/ctdb"
cache_file="$tmp_dir/netcache.$$"

reload_smb()
{
service smb status >/dev/null 2>&1
if [ $? -ne 0 ] ; then
return 0
fi
smbcontrol smbd reload-config >/dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "failed to reload smb service."
return 1
fi

return 0
}

reload_nfs()
{
service nfs-ganesha status >/dev/null 2>&1
if [ $? -ne 0 ] ; then
return 0
fi

service nfs-ganesha reload >/dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "failed to reload nfs service."
return 1
fi
return 0
}

reload_dns()
{
service dnsmasq status >/dev/null 2>&1
if [ $? -ne 0 ] ; then
return 0
fi
service dnsmasq restart >/dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "failed to reload dnsmasq service."
return 1
fi

return 0
}
pull_smb()
{
tmp_smb_file="$tmp_dir/smb.conf.$$"
touch $tmp_smb_file >/dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "failed to create temp file for pull smb config."
return 1
fi

echo "begin to....."
rm -f $cache_file >/dev/null 2>&1
content=$(net registry enumerate "HKLM\Software\Samba\smbconf")
if [ $? -ne 0 ] ||[ x"$content" == x ] ; then
echo "Failed to read smb configuration from registry.tdb."
return 1
fi
for service in ` net registry enumerate 'HKLM\Software\Samba\smbconf' |grep "Keyname"|awk -F= '{print $2}' |sed 's/^[ ]*//g'`
do
echo "service is $service"
echo "[$service]" >> $tmp_smb_file

net registry enumerate "HKLM\Software\Samba\smbconf\\$service" |grep "Valuename" |awk -F= '{print $2}'|sed 's/^[ ]*//g' > $cache_file 2>/dev/null

while read valuename
do
echo "valuename is $valuename"
value=$(net registry getvalueraw "HKLM\Software\Samba\smbconf\\$service" "$valuename")
if [ $? -eq 0 ] ; then
echo "$valuename = $value" >> $tmp_smb_file
fi
done < $cache_file

done

mv $tmp_smb_file /etc/samba/smb.conf
if [ $? -ne 0 ] ; then
echo "failed to override smb.conf."
rm -rf $tmp_smb_file >/dev/null 2>&1
rm -rf $cache_file >/dev/null 2>&1
return 1
fi
rm -rf $tmp_smb_file >/dev/null 2>&1
rm -rf $cache_file >/dev/null 2>&1
reload_smb
if [ $? -ne 0 ] ; then
return 1
fi
return 0
}
pull_nfs()
{
tmp_nfs_file="$tmp_dir/gluster.ganesha.conf.$$"
touch $tmp_nfs_file >/dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "failed to create temp for pull nfs config."
return 1
fi

rm -rf $cache_file >/dev/null 2>&1
content=$(net registry enumerate "HKLM\Software\nfs")
if [ $? -ne 0 ] ; then
echo "Failed to read nfs configuration from registry.tdb."
return 1
fi

for export_id in `net registry enumerate 'HKLM\Software\nfs' |grep "Keyname"|awk -F= '{print $2}' |sed 's/^[ ]*//g'`
do
echo "EXPORT" >> $tmp_nfs_file
echo "{" >> $tmp_nfs_file
net registry enumerate "HKLM\Software\nfs\\$export_id" |grep "Valuename" |awk -F= '{print $2}'|sed 's/^[ ]*//g' > $cache_file 2>/dev/null
while read valuename
do
if [ x"$valuename" == x"Name" -o x"$valuename" == x"Hostname" -o x"$valuename" == x"Volume" ] ; then
continue
fi
value=$(net registry getvalueraw "HKLM\Software\nfs\\$export_id" "$valuename")
if [ $? -eq 0 ] ; then
echo " $valuename = $value" >> $tmp_nfs_file
fi
done < $cache_file

echo "FSAL {" >> $tmp_nfs_file

value=$(net registry getvalueraw "HKLM\Software\nfs\\$export_id" Name)
if [ $? -eq 0 ] ; then
echo " Name = $value" >> $tmp_nfs_file
fi

value=$(net registry getvalueraw "HKLM\Software\nfs\\$export_id" Hostname)
if [ $? -eq 0 ] ; then
echo " Hostname = $value" >> $tmp_nfs_file
fi

value=$(net registry getvalueraw "HKLM\Software\nfs\\$export_id" Volume)
if [ $? -eq 0 ] ; then
echo " Volume = $value" >> $tmp_nfs_file
fi
echo " }" >> $tmp_nfs_file
echo "}" >> $tmp_nfs_file
done

mv $tmp_nfs_file /etc/ganesha/gluster.ganesha.conf
if [ $? -ne 0 ] ; then
echo "Failed to override nfs configuration."
rm -rf $tmp_nfs_file >/dev/null 2>&1
rm -rf $cache_file >/dev/null 2>&1
return 1
fi

rm -rf $tmp_nfs_file >/dev/null 2>&1
rm -rf $cache_file >/dev/null 2>&1
reload_nfs
if [ $? -ne 0 ] ; then
return 1
fi

return 0

}


pull_dns()
{
tmp_dns_file="$tmp_dir/zone.conf.$$"
touch $tmp_dns_file >/dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "failed to create file $tmp_dns_file."
return 1
fi

rm -f $cache_file >/dev/null 2>&1
content=$(net registry enumerate "HKLM\Software\dns")
if [ $? -ne 0 ] ; then
echo "Failed to read dns configuration from registry.tdb."
return 1;

fi

for zone in ` net registry enumerate 'HKLM\Software\dns' |grep "Keyname"|awk -F= '{print $2}' |sed 's/^[ ]*//g'`
do
echo "zone is $zone"
echo "zone $zone" >> $tmp_dns_file
net registry enumerate "HKLM\Software\dns\\$zone" |grep "Valuename" |awk -F= '{print $2}'|sed 's/^[ ]*//g' > $cache_file 2>/dev/null

while read valuename
do
echo "valuename is $valuename"
value=$(net registry getvalueraw "HKLM\Software\dns\\$zone" "$valuename")
if [ $? -eq 0 ] ; then
echo " $valuename $value" >> $tmp_dns_file
fi
done < $cache_file


echo "end zone" >> $tmp_dns_file
done

mv $tmp_dns_file /etc/zone.conf
if [ $? -ne 0 ] ; then
echo "failed to override zone.conf."
rm -rf $tmp_dns_file >/dev/null 2>&1
rm -rf $cache_file >/dev/null 2>&1
return 1
fi
rm -rf $tmp_dns_file >/dev/null 2>&1
rm -rf $cache_file >/dev/null 2>&1
reload_dns
if [ $? -ne 0 ] ; then
return 1
fi

return 0
}

0 comments on commit 8c7d8c9

Please sign in to comment.