1
1
#! /bin/bash
2
2
cd ` dirname $0 `
3
3
4
- need_restart=true
5
- if [ " only_update" = " " $1 ]; then
6
- need_restart=false
7
- fi
8
-
9
4
PID_FILE=" /var/run/tat_agent.pid"
10
5
11
6
# install the agent binary
@@ -14,38 +9,6 @@ PATH_DIR="/usr/sbin/"
14
9
TAT_AGENT=" tat_agent"
15
10
TAT_AGENT32=" tat_agent32"
16
11
17
- # if arch is 32bit and 32bit bin exists, rename `tat_agent32` to `tat_agent`
18
- machine=$( uname -m)
19
- if [ " $machine " != " x86_64" ] && [ -f " $TAT_AGENT32 " ]; then
20
- mv ${TAT_AGENT} -f ${TAT_AGENT} 64
21
- mv ${TAT_AGENT32} -f ${TAT_AGENT}
22
- fi
23
-
24
- # check if agent runnable
25
- chmod +x ${TAT_AGENT}
26
- if ! ./${TAT_AGENT} -V; then
27
- echo " tat_agent not runnable, exit."
28
- exit 1
29
- fi
30
-
31
- mkdir -p ${SERVICE_DIR}
32
- if [ $? -ne 0 ]; then
33
- # handle special case for CoreOS whose /usr is Read-only
34
- grep -q CoreOS /etc/os-release
35
- if [ $? -eq 0 ]; then
36
- SERVICE_DIR=" /var/lib/qcloud/tat_agent/"
37
- mkdir -p ${SERVICE_DIR}
38
- PATH_DIR=" /opt/bin/"
39
- sed -i ' s/\/usr\/local\/qcloud/\/var\/lib\/qcloud/g' tat_agent.service tat_agent_service.conf tat_agent_service uninstall.sh
40
- sed -i ' s/\/usr\/sbin/\/opt\/bin/g' uninstall.sh
41
- else
42
- echo ' Install fail, has no permission, may not root.'
43
- exit 1
44
- fi
45
- fi
46
- cp -f ${TAT_AGENT} ${SERVICE_DIR}
47
- ln -sf ${SERVICE_DIR}${TAT_AGENT} ${PATH_DIR}${TAT_AGENT}
48
-
49
12
has_systemd () {
50
13
[[ ` systemctl` =~ -\. mount ]] > /dev/null 2>&1 && return 0
51
14
if systemctl 2> /dev/null | grep -e " -\.mount" > /dev/null 2>&1 ; then
@@ -74,46 +37,122 @@ has_upstart() {
74
37
return 1
75
38
}
76
39
77
- if has_systemd; then
78
- echo " use systemd to manage service"
79
- SYSTEMD_DIR=" /etc/systemd/system/"
80
- cp -f tat_agent.service ${SYSTEMD_DIR}
81
- systemctl daemon-reload
82
- systemctl enable tat_agent.service
83
- if test " ${need_restart} " = true ; then
84
- systemctl restart tat_agent.service
85
- fi
86
- elif has_upstart; then
87
- echo " use upstart(initctl) to manage service"
88
- cp -f tat_agent_service.conf /etc/init/
89
- if test " ${need_restart} " = true ; then
90
- initctl stop tat_agent_service
91
- initctl start tat_agent_service
92
- fi
93
- elif has_sysvinit; then
94
- cp -f tat_agent_service /etc/init.d/
95
- chmod 755 /etc/init.d/tat_agent_service
96
- /etc/init.d/tat_agent_service restart
97
- which chkconfig > /dev/null 2>&1
98
- if [ $? -eq 0 ]; then
99
- echo " use chkconfig to manage service"
100
- chkconfig --add tat_agent_service
101
- chkconfig tat_agent_service on
102
- else
103
- which update-rc.d > /dev/null 2>&1
104
- if [ $? -eq 0 ]; then
105
- echo " use update-rc.d to manage service"
106
- update-rc.d tat_agent_service defaults
107
- else
108
- echo " no proper daemon manager found, tat_agent can not auto start"
109
- fi
110
- fi
111
- else
112
- echo " no proper daemon manager found, tat_agent can not auto start"
113
- kill ` cat ${PID_FILE} ` > /dev/null 2>&1
114
- sleep 1
115
- rm -f ${PID_FILE}
116
- cd ${SERVICE_DIR}
117
- ./${TAT_AGENT}
118
- echo " tat_agent started"
119
- fi
40
+ install () {
41
+ need_restart=$1
42
+
43
+ # if arch is 32bit and 32bit bin exists, rename `tat_agent32` to `tat_agent`
44
+ machine=$( uname -m)
45
+ if [ " $machine " != " x86_64" ] && [ -f " $TAT_AGENT32 " ]; then
46
+ mv ${TAT_AGENT} -f ${TAT_AGENT} 64
47
+ mv ${TAT_AGENT32} -f ${TAT_AGENT}
48
+ fi
49
+
50
+ # check if agent runnable
51
+ chmod +x ${TAT_AGENT}
52
+ if ! ./${TAT_AGENT} -V; then
53
+ echo " tat_agent not runnable, exit."
54
+ exit 1
55
+ fi
56
+
57
+ mkdir -p ${SERVICE_DIR}
58
+ if [ $? -ne 0 ]; then
59
+ # handle special case for CoreOS whose /usr is Read-only
60
+ grep -q CoreOS /etc/os-release
61
+ if [ $? -eq 0 ]; then
62
+ SERVICE_DIR=" /var/lib/qcloud/tat_agent/"
63
+ mkdir -p ${SERVICE_DIR}
64
+ PATH_DIR=" /opt/bin/"
65
+ sed -i ' s/\/usr\/local\/qcloud/\/var\/lib\/qcloud/g' tat_agent.service tat_agent_service.conf tat_agent_service uninstall.sh
66
+ sed -i ' s/\/usr\/sbin/\/opt\/bin/g' uninstall.sh
67
+ else
68
+ echo ' Install fail, has no permission, may not root.'
69
+ exit 1
70
+ fi
71
+ fi
72
+ cp -f ${TAT_AGENT} ${SERVICE_DIR}
73
+ ln -sf ${SERVICE_DIR}${TAT_AGENT} ${PATH_DIR}${TAT_AGENT}
74
+
75
+ if has_systemd; then
76
+ echo " use systemd to manage service"
77
+ SYSTEMD_DIR=" /etc/systemd/system/"
78
+ cp -f tat_agent.service ${SYSTEMD_DIR}
79
+ systemctl daemon-reload
80
+ systemctl enable tat_agent.service
81
+ if test " ${need_restart} " = true ; then
82
+ systemctl restart tat_agent.service
83
+ fi
84
+ elif has_upstart; then
85
+ echo " use upstart(initctl) to manage service"
86
+ cp -f tat_agent_service.conf /etc/init/
87
+ if test " ${need_restart} " = true ; then
88
+ initctl stop tat_agent_service
89
+ initctl start tat_agent_service
90
+ fi
91
+ elif has_sysvinit; then
92
+ cp -f tat_agent_service /etc/init.d/
93
+ chmod 755 /etc/init.d/tat_agent_service
94
+ # TODO: uncomment following code after 0.1.14 is released.
95
+ # if test "${need_restart}" = true; then
96
+ /etc/init.d/tat_agent_service restart
97
+ # fi
98
+ which chkconfig > /dev/null 2>&1
99
+ if [ $? -eq 0 ]; then
100
+ echo " use chkconfig to manage service"
101
+ chkconfig --add tat_agent_service
102
+ chkconfig tat_agent_service on
103
+ else
104
+ which update-rc.d > /dev/null 2>&1
105
+ if [ $? -eq 0 ]; then
106
+ echo " use update-rc.d to manage service"
107
+ update-rc.d tat_agent_service defaults
108
+ else
109
+ echo " no proper daemon manager found, tat_agent can not auto start"
110
+ fi
111
+ fi
112
+ else
113
+ # TODO: uncomment following code after 0.1.14 is released.
114
+ # if test "${need_restart}" = true; then
115
+ echo " no proper daemon manager found, tat_agent can not auto start"
116
+ PID=$( cat ${PID_FILE} )
117
+ kill ${PID} > /dev/null 2>&1
118
+ sleep 0.1 || sleep 1
119
+ rm -f ${PID_FILE}
120
+ cd ${SERVICE_DIR}
121
+ ./${TAT_AGENT}
122
+ echo " tat_agent started"
123
+ # fi
124
+ fi
125
+ }
126
+
127
+ restart () {
128
+ if has_systemd; then
129
+ echo " use systemd to manage service"
130
+ systemctl restart tat_agent.service
131
+ elif has_upstart; then
132
+ echo " use upstart(initctl) to manage service"
133
+ initctl stop tat_agent_service
134
+ initctl start tat_agent_service
135
+ elif has_sysvinit; then
136
+ /etc/init.d/tat_agent_service restart
137
+ else
138
+ PID=$( cat ${PID_FILE} )
139
+ kill ${PID} > /dev/null 2>&1
140
+ sleep 0.1 || sleep 1
141
+ rm -f ${PID_FILE}
142
+ cd ${SERVICE_DIR}
143
+ ./${TAT_AGENT}
144
+ echo " tat_agent started"
145
+ fi
146
+ }
147
+
148
+ case $1 in
149
+ only_update)
150
+ install false
151
+ ;;
152
+ restart)
153
+ restart
154
+ ;;
155
+ * )
156
+ install true
157
+ ;;
158
+ esac
0 commit comments