10 # A non-annoying way to log stuff
11 # ${@} is all the parameters, also known as the message. Quoting the input
12 # preserves whitespace.
13 msg="`date +'%b %e %Y %T'`: ${@}"
14 echo "${msg}" >> ${LOGFILE}
18 # A non-annoying way to log output of commands
19 # ${@} is all the parameters supplied to the function. just execute it,
20 # and capture the output in a variable. then log that.
23 if [ -n "${output}" ] ; then
24 logger "${1}: ${output}"
30 # Check for the superserver $1 for the config $2
32 xinetd) check_xinetd $2; return $?;;
33 inetd) check_inetd $2; return $?;;
34 launchd) check_launchd $2; return $?;;
35 smf) check_smf $2; return $?;;
40 # Checks for an xinetd install and a config name passed as the first
43 # 0 if the file exists,
45 # 2 if xinetd.d/ does not exist or is a file
47 if [ -d ${SYSCONFDIR}/xinetd.d ] ; then
48 if [ -f ${SYSCONFDIR}/xinetd.d/${1} ] ; then
49 logger "Found existing xinetd config: ${1}"
55 # No xinetd installation.
62 SunOS) inetd_conf=${BASEDIR}/${SYSCONFDIR}/inet/inetd.conf ;;
63 *) inetd_conf=${SYSCONFDIR}/inetd.conf ;;
65 if [ -e ${inetd_conf} ] ; then
66 if grep "${1}" ${inetd_conf} > /dev/null ; then
67 logger "Found existing inetd config: ${1}"
73 # No inetd installation.
79 # TODO: refactor OS X scripts.
84 # Only for solaris! This check only notices if an amanda service is active,
85 # it does not notice server vs client entries.
86 log_output_of svcs -H "*amanda*" || { \
87 logger "No amanda service found."; return 1; }
90 check_superserver_running() {
91 # Check for the given superserver, $1, in the output of ps -ef, or on
95 # 1: $1 is not running
96 # 2: $1 is not valid for this system
98 # Linux or Solaris. This works despite sol10 using SMF.
99 inetd) ps_flags='-e';;
100 xinetd) ps_flags='-e';;
102 launchd) ps_flags='aux';;
103 *) echo "Bad superserver."; return 2 ;;
105 if [ "$1" = "launchd" ] && [ `uname` != 'Darwin' ]; then
106 echo "Only darwin uses launchd"
109 if [ "$1" = "xinetd" ] && [ "$os" = 'SunOS' ] && \
110 [ `uname -r` = "5.10" ]; then
111 echo "Solaris 10 does not use xinetd."
115 PROC=`ps ${ps_flags} | grep -v 'grep'| grep "${1}"`
116 if [ x"${PROC}" != x ]; then
124 log_output_of mv ${SYSCONFDIR}/xinetd.d/${1} ${AMANDAHOMEDIR}/example/xinetd.${1}.orig || \
125 { logger "WARNING: Could not back up existing xinetd configuration '${1}'";
127 logger "Old xinetd config for '${1}' backed up to '${AMANDAHOMEDIR}/example/xinetd.${1}.orig'"
132 SunOS) inetd_conf=${BASEDIR}/${SYSCONFDIR}/inet/inetd.conf ;;
133 *) inetd_conf=${SYSCONFDIR}/inetd.conf ;;
135 # Backs up any amanda configuration it finds
136 log_output_of sed -n "/^amanda .* amandad/w ${AMANDAHOMEDIR}/example/inetd.orig" ${inetd_conf} || \
137 { logger "WARNING: could not write ${AMANDAHOMEDIR}/example/inetd.orig";
139 log_output_of sed "/^amanda .* amandad/d" ${inetd_conf} > \
140 ${inetd_conf}.tmp || \
141 { logger "WARNING: could not write ${inetd_conf}.tmp";
143 log_output_of mv ${inetd_conf}.tmp ${inetd_conf} || \
144 { logger "WARNING: could not overwrite ${inetd_conf}, old config not removed.";
146 logger "Old inetd config for amanda backed up to ${AMANDAHOMEDIR}/example/inetd.orig"
150 # Solaris only. I *think* this should be consistent across all smf installs
151 svccfg -s *amanda* > ${BASEDIR}/${AMANDAHOMEDIR}/example/amanda_smf.xml.orig || {\
152 logger "Warning: export of existing amanda service failed.";
155 log_output_of inetadm -d *amanda* || { \
156 # Not critical, we don't need to return if this fails.
157 logger "Warning: disabling existing amanda service failed."; }
159 log_output_of svccfg delete -f *amanda* || { \
160 logger "Error: removing the old amanda service failed.";
165 log_output_of install -m 0644 ${AMANDAHOMEDIR}/example/xinetd.${1} ${SYSCONFDIR}/xinetd.d/${1} || \
166 { logger "WARNING: Could not install xinetd configuration '${1}'" ; return 1; }
167 logger "Installed xinetd config for ${1}."
172 SunOS) inetd_conf=${BASEDIR}/${SYSCONFDIR}/inet/inetd.conf ;;
173 *) inetd_conf=${SYSCONFDIR}/inetd.conf ;;
175 # This one is hard to log because we're just appending.
176 logger "Appending ${AMANDAHOMEDIR}/example/inetd.conf.${1} to ${inetd_conf}"
177 cat ${AMANDAHOMEDIR}/example/inetd.conf.${1} >> ${inetd_conf}
181 # First parameter should be the name of the service to install
182 # (amandaserver, or amandaclient).
186 # Use inetadm and svcadm.
187 log_output_of ${BASEDIR}/usr/sbin/inetconv -f -i ${AMANDAHOMEDIR}/example/inetd.conf.${1} || { \
188 logger "Warning: Failed to create Amanda SMF manifest. Check the system log.";
190 log_output_of ${BASEDIR}/usr/sbin/inetadm -e svc:/network/amanda/tcp || { \
191 logger "Warning: Failed to enable Amanda service. See system log for more information.";
193 log_output_of ${BASEDIR}/usr/sbin/svcadm restart network/amanda/tcp || { \
194 logger "Warning: Failed to restart Amanda service. See system log for details.";
199 logger "Solaris 8 and 9 use inetd, not SMF tools."
204 # I don't know what to do...
205 logger "ERROR: Unsupported and untested version of Solaris: $ver"
212 # Default action is to try reload.
213 if [ "x$1" = "x" ]; then
215 elif [ "$1" = "reload" -o "$1" = "restart" ]; then
218 logger "WARNING: bad argument to reload_xinetd: $1"
221 if [ "$action" = "reload" ] ; then
222 logger "Reloading xinetd configuration..."
223 log_output_of ${SYSCONFDIR}/init.d/xinetd $action # Don't exit!
224 if [ $? -ne 0 ] ; then
225 logger "xinetd reload failed. Attempting restart..."
226 log_output_of ${SYSCONFDIR}/init.d/xinetd restart || \
227 { logger "WARNING: restart failed." ; return 1; }
231 logger "Restarting xinetd."
232 log_output_of ${SYSCONFDIR}/init.d/xinetd $1 || \
233 { logger "WARNING: ${1} failed." ; return 1; }
238 # Default action is to try reload.
239 if [ "x$1" = "x" ]; then
241 elif [ "$1" = "reload" -o "$1" = "restart" ]; then
244 logger "WARNING: bad argument to reload_inetd: $1"
247 if [ "$1" = "reload" ] ; then
248 logger "Reloading inetd configuration..."
249 log_output_of ${SYSCONFDIR}/init.d/inetd $1 # Don't exit!
250 if [ $? -ne 0 ] ; then
251 logger "inetd reload failed. Attempting restart..."
252 log_output_of ${SYSCONFDIR}/init.d/inetd restart || \
253 { logger "WARNING: restart failed." ; return 1; }
257 logger "Restarting inetd."
258 log_output_of ${SYSCONFDIR}/init.d/inetd $1 || \
259 { logger "WARNING: ${1} failed." ; return 1; }
262 # End Common functions