Skip to content

Commit

Permalink
Add daemon support for docker
Browse files Browse the repository at this point in the history
  • Loading branch information
ellermister committed Jan 24, 2024
1 parent d004bd7 commit aa23570
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ mtproto-proxy
proxy-multi.conf
proxy-secret
build
pid
pid
.idea
4 changes: 2 additions & 2 deletions mtproxy-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set_config(){
sed -i 's/domain="[0-9A-z\.\-]*"/domain="'$domain'"/' $mtp_config
fi
if [ "$provider" ] && [[ "$provider" =~ ^[1-2]$ ]]; then
sed -i 's/provider=[0-9]\+/cat /='$provider'/' $mtp_config
sed -i 's/provider=[0-9]\+/provider='$provider'/' $mtp_config
fi
}

Expand Down Expand Up @@ -53,4 +53,4 @@ echo "=================================================="
echo -e "Default port is \033[31m443\033[0m by docker started mtproxy!!!"
echo "=================================================="
cd /home/mtproxy
bash /home/mtproxy/mtproxy.sh start
bash /home/mtproxy/mtproxy.sh daemon
27 changes: 26 additions & 1 deletion mtproxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ function gen_rand_hex() {
}

info_mtp() {
if is_running_mtp; then
if [[ "$1" == "ingore" ]] || is_running_mtp; then
source ./mtp_config
public_ip=$(get_ip_public)

Expand Down Expand Up @@ -455,6 +455,28 @@ run_mtp() {
fi
}


daemon_mtp() {
cd $WORKDIR

if is_running_mtp; then
echo -e "提醒:\033[33mMTProxy已经运行,请勿重复运行!\033[0m"
else
local command=$(get_run_command)
echo $command
while true
do
{
sleep 2
info_mtp "ingore"
} &
$command >/dev/null 2>&1
echo "进程检测到被关闭,正在重启中!!!"
sleep 2
done
fi
}

debug_mtp() {
cd $WORKDIR

Expand Down Expand Up @@ -509,6 +531,9 @@ param=$1
if [[ "start" == $param ]]; then
echo "即将:启动脚本"
run_mtp
elif [[ "daemon" == $param ]]; then
echo "即将:启动脚本(守护进程)"
daemon_mtp
elif [[ "stop" == $param ]]; then
echo "即将:停止脚本"
stop_mtp
Expand Down

0 comments on commit aa23570

Please sign in to comment.