This repository has been archived by the owner on Apr 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
/
newapp.sh
executable file
·134 lines (107 loc) · 3.26 KB
/
newapp.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/sh
# 快速生成新app
dir=./apps
appname="$1"
service="$2"
appinfo="$3"
tools="$(cat config/version.txt)"
[ -z "$appname" -o -z "$service" -o -z "$appinfo" ] && echo "信息为空(插件名,服务名,介绍)!" && exit
[ -d $dir/$appname ] && echo "插件已存在!" && exit
cd $dir || (mkdir -p $dir && cd $dir)
mkdir -p $appname
mkdir -p $appname/bin
mkdir -p $appname/config
mkdir -p $appname/script
echo "生成插件版本号文件..."
echo 1.0.0 > $appname/config/version.txt
echo "生成插件uci配置文件..."
cat > $appname/config/$appname.uci <<-EOF
uciset="uci set monlor.$appname"
\$uciset=config
\$uciset.service="$service"
\$uciset.appname="$appname"
\$uciset.tools="$tools"
\$uciset.appinfo="$appinfo"
\$uciset.newinfo=""
EOF
echo "生成工具箱配置文件..."
cat > $appname/config/monlor.conf <<EOF
#------------------【$2】--------------------
$appname() {
eval \`ucish export $appname\`
uciset="uci set monlor.\$appname"
echo "********* \$service ***********"
echo "[\$appinfo]"
read -p "启动\$appname服务?[1/0] " enable
checkread \$enable && \$uciset.enable="\$enable"
if [ "\$enable" == '1' ]; then
# Scripts Here
\$monlorpath/apps/\$appname/script/\$appname.sh restart
else
\$monlorpath/apps/\$appname/script/\$appname.sh stop
fi
}
#------------------【$2】--------------------
EOF
echo "生成插件运行脚本..."
cat > $appname/script/$appname.sh <<-EOF
#!/bin/ash /etc/rc.common
source "\$(uci -q get monlor.tools.path)"/scripts/base.sh
eval \`ucish export $appname\`
START=95
STOP=95
SERVICE_USE_PID=1
SERVICE_WRITE_PID=1
SERVICE_DAEMONIZE=1
EXTRA_COMMANDS=" status backup recover"
EXTRA_HELP=" status Get \$appname status"
start() {
[ -n "\$(pidof \$appname)" ] && logsh "【\$service】" "\$appname已经在运行!" && exit 1
logsh "【\$service】" "正在启动\$appname服务... "
# cru a "\$appname" "0 6 * * * \$monlorpath/apps/\$appname/script/\$appname.sh restart"
# Scripts Here
# iptables -I INPUT -p tcp --dport \$port -m comment --comment "monlor-\$appname" -j ACCEPT
service_start \$BIN/\$appname
[ \$? -ne 0 ] && logsh "【\$service】" "启动\$appname服务失败!" && end
logsh "【\$service】" "启动\$appname服务完成!"
}
stop() {
logsh "【\$service】" "正在停止\$appname服务... "
[ "\$enable" == '0' ] && destroy
service_stop \$BIN/\$appname
kill -9 "\$(pidof \$appname)"
# iptables -D INPUT -p tcp --dport \$port -m comment --comment "monlor-\$appname" -j ACCEPT > /dev/null 2>&1
}
destroy() {
# End app, Scripts here
# cru d "\$appname"
return
}
end() {
uci set monlor.\$appname.enable=0
uci commit monlor
stop
exit 1
}
restart() {
stop
sleep 1
start
}
status() {
if [ -n "\$(pidof \$appname)" ]; then
echo -e "运行中\n1"
else
echo -e "未运行\n0"
fi
}
backup() {
mkdir -p \$monlorbackup/\$appname
# Backup scripts here
return
}
recover() {
# Recover scripts here
return
}
EOF