-
Notifications
You must be signed in to change notification settings - Fork 2
/
db2
116 lines (95 loc) · 2.47 KB
/
db2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#
# Author: ruggero DOT marchei AT daemonzone DOT net
# Version: 1.00
#
# chkconfig: - 30 70
# description: start/stop a db2 instance
# Source function library.
[[ -f /etc/init.d/functions ]] || exit 1
. /etc/init.d/functions
##########################################################
# Set the Instance owner:
DB2USER=
# [OPTIONAL] Set the db2nodes.cfg (DB2 ESE only):
DB2NODES_CFG="0 ${HOSTNAME} 0"
##########################################################
# Exit if the Instance owner is not set
[[ -n ${DB2USER} ]] || { echo "Instance owner not set" && exit 1; }
HOSTNAME=`hostname -f`
RETVAL=0
find_homedir() {
getent passwd $1 | cut -d":" -f 6
}
start() {
LOGFILE=$(mktemp)
INSTHOME="$(find_homedir ${DB2USER})"
[[ -n ${DB2NODES_CFG} ]] && echo ${DB2NODES_CFG} > ${INSTHOME}/sqllib/db2nodes.cfg
echo -n $"Starting IBM DB2 instance [${DB2USER}]"
daemon --user=${DB2USER} "\
source ${INSTHOME}/sqllib/db2profile; \
db2start" >${LOGFILE} 2>&1 && success || failure
RETVAL=$?
[[ $RETVAL -ne 0 ]] && cat ${LOGFILE}
rm -f ${LOGFILE}
echo ""
}
status() {
INSTHOME="$(find_homedir ${DB2USER})"
su - ${DB2USER} -c "\
source ${INSTHOME}/sqllib/db2profile; \
db2gcf -s" > /dev/null 2>&1
RETVAL=$?
}
stop() {
LOGFILE=$(mktemp)
INSTHOME="$(find_homedir ${DB2USER})"
echo -n $"Stopping IBM DB2 instance [${DB2USER}]"
# Is DB2 already stopped?
status
if [ $RETVAL -ne 0 ]; then
# Already stopped return 0
success
RETVAL=0
echo ""
else
daemon --user=${DB2USER} "\
source ${INSTHOME}/sqllib/db2profile; \
db2stop force" >${LOGFILE} 2>&1 && success || failure
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
daemon --user=${DB2USER} "\
source ${INSTHOME}/sqllib/db2profile; \
db2_kill" >>${LOGFILE} 2>&1 && success || failure
fi
echo ""
fi
[[ $RETVAL -ne 0 ]] && cat ${LOGFILE}
rm -f ${LOGFILE}
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
if [ $RETVAL -gt 0 ]; then
echo "DB2 instance ${DB2USER} is not running"
else
echo "DB2 instance ${DB2USER} is running"
fi
;;
restart)
stop
sleep 3
start
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=1
;;
esac
exit $RETVAL