4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the License).
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/CDDL.txt
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/CDDL.txt.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets [] replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #ident "%Z%%M% %I% %E% SMI"
29
30 TASK_COMMAND=""
31
32 ZONENAME=/usr/bin/zonename
33
34 SCLOGGER=/usr/cluster/lib/sc/scds_syslog
35 LOGGER=/usr/bin/logger
36 SCHA_RESOURCE_SETSTATUS=/usr/cluster/bin/scha_resource_setstatus
37 SCHA_RESOURCE_GET=/usr/cluster/bin/scha_resource_get
38 SCHA_RESOURCEGROUP_GET=/usr/cluster/bin/scha_resourcegroup_get
39 PMFADM=/usr/cluster/bin/pmfadm
40 UNAME=/usr/bin/uname
41 ECHO=/usr/bin/echo
42 AWK=/usr/bin/awk
43 EGREP=/usr/bin/egrep
44 PROJECTS=/usr/bin/projects
45
46 terminate()
47 {
48
49 debug_message "Function: terminate - Begin"
50 ${SET_DEBUG}
51
52 exiting_func=${1}
53 exit_code=${2}
54
55 # determine the right return code, it is either the return code from the functions or
56 # the appropriate smf return code
57
58 if in_cluster
59 then
60
61 # called in a clustered global zone
62
63 debug_message "Method: ${MYNAME} ${exiting_func} - End (${exit_code})"
64 exit ${exit_code}
127 done
128
129 shift $((${OPTIND} - 1))
130 LOG_STRING=`/usr/bin/printf "$@"`
131
132 ${LOGGER} -p ${PRI} -t ${TAG} ${LOG_STRING}
133 fi
134
135 }
136
137 rgs_zonename()
138 {
139
140 # Determine wether the host specified by uname -n is combined with a zonename in the
141 # current resourcegroups nodelist. The seperator beween nodename and zonename is ":".
142 #
143 # This function assume the resource group name preset in the variable ${RESOURCEGROUP} and should be called
144 #
145 # $(rgs_zonename)
146 #
147 # It passes back the zonename or nothing.
148
149 debug_message "Function: rg_zonename - Begin "
150 ${SET_DEBUG}
151
152 nodes_zone=
153 nodename=`${UNAME} -n`
154 node=`${SCHA_RESOURCEGROUP_GET} -G ${RESOURCEGROUP} -O NODELIST|grep ${nodename}`
155
156 if ${ECHO} ${node} | grep : >/dev/null 2>&1
157 then
158 nodes_zone=`${ECHO} ${node} | ${AWK} -F: '{print $2}'`
159
160 fi
161
162 print ${nodes_zone}
163
164 debug_message "Function: rg_zonename - End "
165 }
166
167 debug_message()
168 {
169 #
170 # Output a debug message to syslog if required
171 #
172
173 if [ -n "${DEBUG}" ]
174 then
175
176 # determine if we should display a message and do it
177
178 if [ "${DEBUG}" = "ALL" ]
472 # @user_action-3
473 # check the validity of the service. there might be a dependency
474 # problem, a sub resource has been restarted, and functionality
475 # might have been impaired
476 # @user_action-4
477 # check the validity of the service. there might be a dependency
478 # problem, a sub resource has been restarted, and functionality
479 # might have been impaired
480 scds_syslog -p daemon.err -t $(syslog_tag) -m \
481 "restart_dependency - Dependent resource to resource %s has been restarted, restart this resource %s" \
482 "${RESOURCE}" "${RESOURCE}"
483
484 St=100
485 else
486 St=0
487 fi
488
489 debug_message "Function: restart_dependency - End"
490
491 return ${St}
492 }
|
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the License).
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/CDDL.txt
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/CDDL.txt.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets [] replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #ident "%Z%%M% %I% %E% SMI"
29
30 TASK_COMMAND=""
31
32 ZONENAME=/usr/bin/zonename
33
34 SCLOGGER=/usr/cluster/lib/sc/scds_syslog
35 LOGGER=/usr/bin/logger
36 SCHA_RESOURCE_SETSTATUS=/usr/cluster/bin/scha_resource_setstatus
37 SCHA_RESOURCE_GET=/usr/cluster/bin/scha_resource_get
38 SCHA_RESOURCEGROUP_GET=/usr/cluster/bin/scha_resourcegroup_get
39 PMFADM=/usr/cluster/bin/pmfadm
40 UNAME=/usr/bin/uname
41 ECHO=/usr/bin/echo
42 AWK=/usr/bin/awk
43 EGREP=/usr/bin/egrep
44 GREP=/usr/bin/grep
45 PROJECTS=/usr/bin/projects
46 WC=/usr/bin/wc
47 CAT=/usr/bin/cat
48 ENV=/usr/bin/env
49 RM=/usr/bin/rm
50 SSH_AGENT=/usr/bin/ssh-agent
51 SSH_ADD=/usr/bin/ssh-add
52 CHMOD=/usr/bin/chmod
53
54 terminate()
55 {
56
57 debug_message "Function: terminate - Begin"
58 ${SET_DEBUG}
59
60 exiting_func=${1}
61 exit_code=${2}
62
63 # determine the right return code, it is either the return code from the functions or
64 # the appropriate smf return code
65
66 if in_cluster
67 then
68
69 # called in a clustered global zone
70
71 debug_message "Method: ${MYNAME} ${exiting_func} - End (${exit_code})"
72 exit ${exit_code}
135 done
136
137 shift $((${OPTIND} - 1))
138 LOG_STRING=`/usr/bin/printf "$@"`
139
140 ${LOGGER} -p ${PRI} -t ${TAG} ${LOG_STRING}
141 fi
142
143 }
144
145 rgs_zonename()
146 {
147
148 # Determine wether the host specified by uname -n is combined with a zonename in the
149 # current resourcegroups nodelist. The seperator beween nodename and zonename is ":".
150 #
151 # This function assume the resource group name preset in the variable ${RESOURCEGROUP} and should be called
152 #
153 # $(rgs_zonename)
154 #
155 # It passes back a zonename or nothing.
156 # If there are more than one zones in the nodelist, it passes back either the zone where the resource group
157 # is online or first one in the list.
158
159 debug_message "Function: rg_zonename - Begin "
160 ${SET_DEBUG}
161
162 nodes_zone=
163 nodename=`${UNAME} -n`
164 node=`${SCHA_RESOURCEGROUP_GET} -G ${RESOURCEGROUP} -O NODELIST|${EGREP} "${nodename}$|${nodename}:"`
165
166 if ${ECHO} ${node} | ${GREP} : >/dev/null 2>&1
167 then
168 if [ `${ECHO} ${node}|${WC} -w` -gt 1 ]
169 then
170 online=0
171 for i in ${node}
172 do
173 if ${SCHA_RESOURCEGROUP_GET} -G ${RESOURCEGROUP} -O RG_state_node ${i}| ${GREP} -i online >/dev/null 2>&1
174 then
175 nodes_zone=`${ECHO} ${i} | ${AWK} -F: '{print $2}'`
176 online=1
177 fi
178 done
179
180 # check if we found a zone where the resource group is online, if not pick the first zone in the list
181
182 if [ ${online} -eq 0 ]
183 then
184 first_node=`${ECHO} ${node} | ${AWK} '{print $1}'`
185 nodes_zone=`${ECHO} ${first_node} | ${AWK} -F: '{print $2}'`
186 fi
187 else
188 nodes_zone=`${ECHO} ${node} | ${AWK} -F: '{print $2}'`
189 fi
190
191 fi
192
193 print ${nodes_zone}
194
195 debug_message "Function: rg_zonename - End "
196 }
197
198 debug_message()
199 {
200 #
201 # Output a debug message to syslog if required
202 #
203
204 if [ -n "${DEBUG}" ]
205 then
206
207 # determine if we should display a message and do it
208
209 if [ "${DEBUG}" = "ALL" ]
503 # @user_action-3
504 # check the validity of the service. there might be a dependency
505 # problem, a sub resource has been restarted, and functionality
506 # might have been impaired
507 # @user_action-4
508 # check the validity of the service. there might be a dependency
509 # problem, a sub resource has been restarted, and functionality
510 # might have been impaired
511 scds_syslog -p daemon.err -t $(syslog_tag) -m \
512 "restart_dependency - Dependent resource to resource %s has been restarted, restart this resource %s" \
513 "${RESOURCE}" "${RESOURCE}"
514
515 St=100
516 else
517 St=0
518 fi
519
520 debug_message "Function: restart_dependency - End"
521
522 return ${St}
523 }
524
525 start_ssh_agent()
526 {
527 #
528 # Start an ssh-agent and add the decrypted private key.
529 # Only when the ssh-agent contains the private key, a ssh login without a
530 # passphrase challenge is possible.
531 #
532 # This function stores the environment variables SSH_AUTH_SOCK and
533 # SSH_AGENT_PID in /tmp/${RESOURCE}-ssh in a ksh compatible format.
534 #
535 # The start_ssh_agent function is meant to be called in the target users
536 # environment.
537 #
538 # The only necessary parameter is the passphrase of the target users
539 # private ssh key.
540 # If you use this function you should kill the started ssh-agent in your
541 # stop function.
542 #
543 # To do this you have to export the SSH_AGENT_PID from tmp/${RESOURCE}-ssh
544 # in the users environment and call /usr/bin/ssh-agent -k.
545 #
546 # The returncode of the start_ssh_agent function is 0 for success, and 1 for error.
547
548 debug_message "Function: start_ssh_agent - Begin"
549 ${SET_DEBUG}
550
551 SSH_PASS=${1}
552
553 rc_start_ssh_agent=0
554 export DISPLAY=""
555
556 # remove the SSH_ASKPASS script and the temporary store of SSH_AUTH_SOCK
557 # and SSH_AGENT_PID to satisfy noclobber
558
559 ${RM} /tmp/${RESOURCE}-askpass 2>/dev/null
560 ${RM} /tmp/${RESOURCE}-ssh 2>/dev/null
561
562 # start the ssh-agent
563
564 eval `${SSH_AGENT} -s` >/dev/null 2>&1
565 if [ ${?} -eq 0 ]
566 then
567 debug_message "Function: start_ssh_agent - ssh-agent started"
568
569 ${ENV} | ${EGREP} "SSH_AUTH_SOCK|SSH_AGENT_PID">/tmp/${RESOURCE}-ssh
570
571 # create the SSH_ASKPASS script needed for a headless ssh-agent
572
573 export SSH_ASKPASS=/tmp/${RESOURCE}-askpass
574 ${CAT} > ${SSH_ASKPASS} <<EOF
575 #!/usr/bin/ksh
576 # reads a passphrase at the ssh-agent command
577 read x
578 ${ECHO} \${x}
579 EOF
580 ${CHMOD} +x ${SSH_ASKPASS}
581
582 # decrypt the private key and store it in memory
583
584 if print ${SSH_PASS}|${SSH_ADD} >/dev/null 2>&1
585 then
586 debug_message "Function: start_ssh_agent - ssh-add successful, private key decryped and stored"
587 else
588 # SCMSGS
589 # @explanation
590 # The ssh passphrase passed to the start_ssh_agent function is wrong
591 # @user_action
592 # Fix the ssh passphrase entry in your parameters
593 scds_syslog -p daemon.err -t $(syslog_tag) -m \
594 "start_ssh_agent: The passphrase %s is wrong" \
595 "${SSH_PASS}"
596 rc_start_ssh_agent=1
597 fi
598
599 # remove the previously created askpass script
600
601 ${RM} ${SSH_ASKPASS}
602 else
603 # SCMSGS
604 # @explanation
605 # The ssh-agent is not startable for the given user
606 # @user_action
607 # Determine and fix the root cause by running the ssh-agent manually
608 # as the target user
609 scds_syslog -p daemon.err -t $(syslog_tag) -m \
610 "start_ssh_agent: The start of the ssh-agent was unsuccessful"
611 rc_start_ssh_agent=1
612
613 fi
614
615 debug_message "Function: start_ssh_agent - End"
616 return ${rc_start_ssh_agent}
617
618 }
|