-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathinstall.sh
executable file
·89 lines (82 loc) · 1.71 KB
/
install.sh
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
#!/bin/sh
SCRIPTS_ROOT=etc/init
APP_PATH=$PWD
INIT_TYPE=""
get_init_type() {
comm=$(cat /proc/1/comm)
if [ "$comm" = "systemd" ]; then
INIT_TYPE="systemd"
return
elif [ "$comm" = "init" ]; then
ver=$(/sbin/init --version 2>/dev/null | grep upstart)
if [ -n "$ver" ]; then
INIT_TYPE="upstart"
return
fi
fi
INIT_TYPE="sysvinit"
}
install() {
case $INIT_TYPE in
"systemd" )
echo install in systemd init
if [ -d /usr/lib/systemd/system ]; then
dst_path="/usr/lib/systemd/system"
elif [ -d /lib/systemd/system ]; then
dst_path="/lib/systemd/system"
else
dst_path="/etc/systemd/system"
fi
cp $SCRIPTS_ROOT/systemd/sysmon.service $dst_path/
sed -i "s|APP_PATH|$APP_PATH|g" $dst_path/sysmon.service
systemctl daemon-reload
systemctl enable sysmon
systemctl start sysmon
;;
"upstart" )
echo install in upstart init
cp $SCRIPTS_ROOT/upstart/sysmon.conf /etc/init/sysmon.conf
sed -i "s|APP_PATH=.*|APP_PATH=\"$APP_PATH\"|g" /etc/init/sysmon.conf
service sysmon start
;;
"sysvinit" )
echo install in sysvinit init
;;
* )
echo install in unknown init
;;
esac
}
uninstall() {
case $INIT_TYPE in
"systemd" )
echo uninstall sysmon from systemd init
systemctl stop sysmon
rm -rvf /lib/systemd/system/sysmon.service
find /etc/systemd/system -name "sysmon.*" | xargs rm -vf
systemctl daemon-reload
;;
"upstart" )
rm -rvf /etc/init/sysmon.conf
echo uninstall sysmon from upstart init
;;
"sysvinit" )
echo uninstall sysmon from sysvinit init
;;
* )
echo uninstall sysmon from unknown init
;;
esac
}
get_init_type
case $1 in
u | -u | --uninstall )
uninstall
;;
h | -h | --help )
show_help
;;
* )
install
;;
esac