-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.sh
88 lines (65 loc) · 1.65 KB
/
manager.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
domain='docker.kiuber.me'
ss_image_name='ss-alpine'
ss_image_version=1.0.0
ss_image="$domain/$ss_image_name:$ss_image_version"
ss_container='ss'
ss_config_in_host="$PWD/config/shadowsocks.json"
ss_config_in_container='/etc/shadowsocks.json'
py_files_in_host="$PWD/appupy/py-files"
py_files_in_container='/opt'
source "$PWD/appupy/base-bash/_base.sh"
source "$PWD/appupy/base-bash/_docker.sh"
function build_ss() {
local cmd="docker build -t $ss_image $PWD/docker"
_run_cmd "$cmd"
}
function build_images() {
build_ss
}
function run() {
local cmd="docker run --name $ss_container"
cmd="$cmd -v $ss_config_in_host:$ss_config_in_container"
cmd="$cmd -v $py_files_in_host:$py_files_in_container"
cmd="$cmd -p 8127:80"
cmd="$cmd -d --privileged=true $ss_image ssserver -c $ss_config_in_container"
_run_cmd "$cmd"
}
function stop() {
_remove_container $ss_container
}
function start() {
run
}
function restart() {
_remove_container $ss_container
run
}
function show_qrcode() {
local hostname=$2
local port=$3
local cmd='python /opt/qrcode.py $hostname $port'
_send_cmd_to_container $ss_container "$cmd"
}
function to_ss() {
_send_cmd_to_container $ss_container 'sh'
}
function logs() {
local cmd="docker logs -f $ss_container"
_run_cmd "$cmd"
}
function help() {
cat <<-EOF
Valid options are:
build_images
run
stop
start
restart
show_qrcode (\$hostname, \$port)
to_ss
logs
help show this help message and exit
EOF
}
action=${1:-help}
$action "$@"