Guest User

conntrackd

a guest
Sep 29th, 2010
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.52 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Conntrackd for initating active/backup state sync between two nodes
  4. # code based on Dummy template and primary-backup.sh
  5. #
  6. # Copyright (C) 2010 op5 AB, Jonathan Petersson <[email protected]>
  7. #                    All Rights Reserved.
  8. # Copyright (C) 2008 by Pablo Neira Ayuso <[email protected]>
  9. #                    All Rights Reserved.
  10. # Copyright (C) 2004 SUSE LINUX AG, Lars Marowsky-Brée
  11. #                    All Rights Reserved.
  12. #
  13. # Disclamer:
  14. # This software has only been tested on Debian Lenny, modifications
  15. # may be needed for other distributions and operating-systems.
  16. #
  17. # Conntrackd will get started automatically if it's not already
  18. # running. However there's no active error-handling for startup errors
  19. # please refer to conntrackd regular error-logs for trouble shooting.
  20. #
  21. # This program is free software; you can redistribute it and/or modify
  22. # it under the terms of version 2 of the GNU General Public License as
  23. # published by the Free Software Foundation.
  24. #
  25. # This program is distributed in the hope that it would be useful, but
  26. # WITHOUT ANY WARRANTY; without even the implied warranty of
  27. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  28. #
  29. # Further, this software is distributed without any warranty that it is
  30. # free of the rightful claim of any third person regarding infringement
  31. # or the like.  Any license provided herein, whether implied or
  32. # otherwise, applies only to this software file.  Patent licenses, if
  33. # any, provided herein do not apply to combinations of this program with
  34. # other software, or any other product whatsoever.
  35. #
  36. # You should have received a copy of the GNU General Public License
  37. # along with this program; if not, write the Free Software Foundation,
  38. # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  39. #
  40.  
  41. #######################################################################
  42. # Initialization:
  43.  
  44. : ${OCF_FUNCTIONS_DIR=/usr/lib/ocf/resource.d/heartbeat}
  45. . ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs
  46.  
  47. #######################################################################
  48.  
  49. # Fill in some defaults if no values are specified
  50. OCF_RESKEY_binary_default="/usr/sbin/conntrackd"
  51. OCF_RESKEY_config_default="/etc/conntrackd/conntrackd.conf"
  52. OCF_RESKEY_lockfile_default="/var/lock/conntrack.lock"
  53.  
  54. : ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
  55. : ${OCF_RESKEY_config=${OCF_RESKEY_config_default}}
  56. : ${OCF_RESKEY_lockfile=${OCF_RESKEY_lockfile_default}}
  57.  
  58. CONNTRACKD="${OCF_RESKEY_binary} -C ${OCF_RESKEY_config}"
  59.  
  60. meta_data() {
  61.     cat <<EOF
  62. <?xml version="1.0"?>
  63. <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
  64. <resource-agent name="Conntrackd" version="0.6">
  65. <version>0.6</version>
  66.  
  67. <longdesc lang="en">
  68. This is a Conntrackd resource to manage primary and secondary state between two firewalls in a cluster.
  69. </longdesc>
  70. <shortdesc lang="en">Manages primary/backup conntrackd state</shortdesc>
  71.  
  72. <parameters>
  73. <parameter name="binary" unique="0">
  74. <longdesc lang="en">
  75. Location of conntrackd binary.
  76. </longdesc>
  77. <shortdesc lang="en">Conntrackd bin</shortdesc>
  78. <contect type="string" default="${OCF_RESKEY_binary_default}"/>
  79. </parameter>
  80.  
  81. <parameter name="config" unique="0">
  82. <longdesc lang="en">
  83. Location of conntrackd configuration file.
  84. </longdesc>
  85. <shortdesc lang="en">Conntrackd config</shortdesc>
  86. <contect type="string" default="${OCF_RESKEY_config_default}"/>
  87. </parameter>
  88.  
  89. <parameter name="lockfile" unique="0">
  90. <longdesc lang="en">
  91. Location of conntrackd lock-file.
  92. </longdesc>
  93. <shortdesc lang="en">Conntrackd lock-file</shortdesc>
  94. <contect type="string" default="${OCF_RESKEY_lockfile_default}"/>
  95. </parameter>
  96.  
  97. </parameters>
  98.  
  99. <actions>
  100. <action name="start"        timeout="20" />
  101. <action name="stop"         timeout="20" />
  102. <action name="monitor"      timeout="20" interval="10" depth="0" />
  103. <action name="reload"       timeout="20" />
  104. <action name="migrate_to"   timeout="20" />
  105. <action name="migrate_from" timeout="20" />
  106. <action name="meta-data"    timeout="5" />
  107. <action name="validate-all"   timeout="20" />
  108. </actions>
  109. </resource-agent>
  110. EOF
  111. }
  112.  
  113. #######################################################################
  114.  
  115. conntrackd_usage() {
  116.     cat <<EOF
  117. usage: $0 {start|stop|monitor|migrate_to|migrate_from|validate-all|meta-data}
  118.  
  119. Expects to have a fully populated OCF RA-compliant environment set.
  120. EOF
  121. }
  122.  
  123. conntrackd_start() {
  124.  
  125.     # Call monitor to verify that conntrackd is running
  126.     conntrackd_monitor
  127.    
  128.     if [ $? -eq  $OCF_SUCCESS ]; then
  129.    
  130.     # commit the external cache into the kernel table
  131.     ocf_run $CONNTRACKD -c || exit $OCF_ERR_GENERIC
  132.    
  133.     # flush the internal and the external caches
  134.     ocf_run $CONNTRACKD -f || exit "asd".$OCF_ERR_GENERIC
  135.    
  136.     # resynchronize my internal cache to the kernel table
  137.     ocf_run $CONNTRACKD -R || exit $OCF_ERR_GENERIC
  138.    
  139.     # send a bulk update to backups
  140.     ocf_run $CONNTRACKD -B || exit $OCF_ERR_GENERIC
  141.    
  142.     return $OCF_SUCCESS
  143.     fi
  144. }
  145.  
  146. conntrackd_stop() {
  147.  
  148.     # Call monitor to verify that conntrackd is running
  149.     conntrackd_monitor
  150.    
  151.     if [ $? =  $OCF_SUCCESS ]; then
  152.    
  153.     # shorten kernel conntrack timers to remove the zombie entries.
  154.     $CONNTRACKD -t
  155.     if [ $? -eq 1 ]
  156.     then
  157.         return $OCF_ERR_GENERIC
  158.     fi
  159.    
  160.     # request resynchronization with the master firewall replica
  161.     $CONNTRACKD -n
  162.     if [ $? -eq 1 ]
  163.     then
  164.         return $OCF_ERR_GENERIC
  165.     fi
  166.    
  167.     fi
  168.    
  169.     return $OCF_SUCCESS
  170. }
  171.  
  172. conntrackd_monitor() {
  173.    
  174.     local conntrackd_pid
  175.     conntrackd_pid=`pidof ${OCF_RESKEY_binary}`
  176.    
  177.     if [ -f $OCF_RESKEY_lockfile ]; then
  178.     if [ -n $conntrackd_pid ]; then
  179.         if [ -n `${OCF_RESKEY_binary} -s | grep "cache internal" > /dev/null` ]; then
  180.         return $OCF_SUCCESS
  181.         else
  182.         return $OCF_ERR_GENERIC
  183.         fi
  184.     else
  185.         return $OCF_ERR_GENERIC
  186.     fi
  187.     else
  188.     $OCF_NOT_RUNNING
  189.     fi
  190. }
  191.  
  192. conntrackd_validate() {
  193.  
  194.     # Check if conntrackd config exists
  195.     if [ ! -f ${OCF_RESKEY_config} ]; then
  196.     return $OCF_ERR_INSTALLED
  197.     fi
  198.    
  199.     return $OCF_SUCCESS
  200. }
  201.  
  202. case $__OCF_ACTION in
  203. meta-data)  meta_data
  204.         exit $OCF_SUCCESS
  205.         ;;
  206. start)      conntrackd_validate
  207.             conntrackd_start
  208.         ;;
  209. stop)       conntrackd_validate
  210.         conntrackd_stop
  211.         ;;
  212. monitor)    conntrackd_validate
  213.             conntrackd_monitor
  214.         ;;
  215. reload)     conntrackd_validate
  216.         ocf_log err "Reloading..."
  217.             conntrackd_start
  218.         ;;
  219. validate-all)   conntrackd_validate;;
  220. usage|help) conntrackd_usage
  221.         exit $OCF_SUCCESS
  222.         ;;
  223. *)      conntrackd_usage
  224.         exit $OCF_ERR_UNIMPLEMENTED
  225.         ;;
  226. esac
  227. rc=$?
  228. ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
  229. exit $rc
Advertisement
Add Comment
Please, Sign In to add comment