Skip to content

Commit d9c56c9

Browse files
author
zhengshuxin
committed
Service templates support SO_REUSEPORT option
1 parent 8db0c44 commit d9c56c9

File tree

7 files changed

+92
-15
lines changed

7 files changed

+92
-15
lines changed

config.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,30 @@ import (
1111
"strings"
1212
)
1313

14-
const Version string = "1.0.8"
14+
const Version string = "1.0.9"
1515

1616
type Config struct {
1717
Entries map[string]string
1818
}
1919

2020
// from configure file of the app
2121
var (
22-
AppConf *Config
23-
AppService string
24-
AppLogPath string
25-
AppOwner string
26-
AppArgs string
27-
AppRootDir string
22+
AppConf *Config
23+
AppService string
24+
AppLogPath string
25+
AppOwner string
26+
AppArgs string
27+
AppRootDir string
2828
AppUseLimit = 0
2929
AppIdleLimit = 0
30+
AppReusePort = false
3031
AppQuickAbort = false
3132
AppWaitLimit = 10
3233
AppAccessAllow = "all"
3334
Appthreads = 0
3435

35-
TlsCertFile string
36-
TlsKeyFile string
36+
TlsCertFile string
37+
TlsKeyFile string
3738
)
3839

3940
func loadConf(confPath string) {
@@ -54,6 +55,7 @@ func loadConf(confPath string) {
5455
AppService = AppConf.GetString("master_service")
5556
AppOwner = AppConf.GetString("master_owner")
5657
AppArgs = AppConf.GetString("master_args")
58+
AppReusePort = AppConf.GetBool("master_reuseport")
5759

5860
AppRootDir = AppConf.GetString("app_queue_dir")
5961
AppUseLimit = AppConf.GetInt("app_use_limit")

examples/gin-server/gin-server.cf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@ service gin-server {
1010
# 当子进程异常退出时,如果该值非空,则将子进程异常退出的消息通知该服务
1111
# master_notify_addr = 127.0.0.1:5801
1212
# 邮件通知接收者
13-
# master_notify_recipients = [email protected]
13+
# master_notify_recipients = [email protected]
14+
15+
# 停止子进程时是否采用强行停止的方式(即给子进程发送 SIGTERM 信号)
16+
master_stop_kill = false
17+
# 当 master_stop_kill 为 true 时,该配置决定是否要等待子进程退出
18+
master_stop_wait = false
19+
20+
# 当系统支持 SO_REUSEPORT 时,是否启用该功能
21+
master_reuseport = no
22+
# 当启用 SO_REUSEPORT 时(即 master_reuseport=yes 时), 是否需要 acl_master
23+
# 也监听该地址, 对于使用旧版 acl(< 3.5.3-17) 编写的服务, 必须将此项设为
24+
# yes, 即: master_reuseport_listen = yes; 对于使用 acl 版本 >= 3.5.3-17
25+
# 编写的服务需设置为 no; 当 master_reuseport=no时,该项设置将被忽略; 当未
26+
# 设置此项时内部缺省值为 yes. 以便使 acl_master 保持对于旧版服务的兼容性.
27+
master_reuseport_listen = no
1428

1529
# 是否允许延迟接受客户端连接,如果为0则表示关闭该功能,如果大于0则表示打开此功能
1630
# 并且此值代表延迟接受连接的超时值,超过此值时如果客户端依然没有发来数据,则操作

examples/go-echod/go-echod.cf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,21 @@ service echo {
1313
# 当子进程异常退出时,如果该值非空,则将子进程异常退出的消息通知该服务
1414
# master_notify_addr = 127.0.0.1:5801
1515
# 邮件通知接收者
16-
# master_notify_recipients = [email protected]
16+
# master_notify_recipients = [email protected]
17+
18+
# 停止子进程时是否采用强行停止的方式(即给子进程发送 SIGTERM 信号)
19+
master_stop_kill = false
20+
# 当 master_stop_kill 为 true 时,该配置决定是否要等待子进程退出
21+
master_stop_wait = false
22+
23+
# 当系统支持 SO_REUSEPORT 时,是否启用该功能
24+
master_reuseport = no
25+
# 当启用 SO_REUSEPORT 时(即 master_reuseport=yes 时), 是否需要 acl_master
26+
# 也监听该地址, 对于使用旧版 acl(< 3.5.3-17) 编写的服务, 必须将此项设为
27+
# yes, 即: master_reuseport_listen = yes; 对于使用 acl 版本 >= 3.5.3-17
28+
# 编写的服务需设置为 no; 当 master_reuseport=no时,该项设置将被忽略; 当未
29+
# 设置此项时内部缺省值为 yes. 以便使 acl_master 保持对于旧版服务的兼容性.
30+
master_reuseport_listen = no
1731

1832
# 是否允许延迟接受客户端连接,如果为0则表示关闭该功能,如果大于0则表示打开此功能
1933
# 并且此值代表延迟接受连接的超时值,超过此值时如果客户端依然没有发来数据,则操作

examples/go-httpd/go-httpd.cf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@ service go-httpd {
1010
# 当子进程异常退出时,如果该值非空,则将子进程异常退出的消息通知该服务
1111
# master_notify_addr = 127.0.0.1:5801
1212
# 邮件通知接收者
13-
# master_notify_recipients = [email protected]
13+
# master_notify_recipients = [email protected]
14+
15+
# 停止子进程时是否采用强行停止的方式(即给子进程发送 SIGTERM 信号)
16+
master_stop_kill = false
17+
# 当 master_stop_kill 为 true 时,该配置决定是否要等待子进程退出
18+
master_stop_wait = false
19+
20+
# 当系统支持 SO_REUSEPORT 时,是否启用该功能
21+
master_reuseport = no
22+
# 当启用 SO_REUSEPORT 时(即 master_reuseport=yes 时), 是否需要 acl_master
23+
# 也监听该地址, 对于使用旧版 acl(< 3.5.3-17) 编写的服务, 必须将此项设为
24+
# yes, 即: master_reuseport_listen = yes; 对于使用 acl 版本 >= 3.5.3-17
25+
# 编写的服务需设置为 no; 当 master_reuseport=no时,该项设置将被忽略; 当未
26+
# 设置此项时内部缺省值为 yes. 以便使 acl_master 保持对于旧版服务的兼容性.
27+
master_reuseport_listen = no
1428

1529
# 是否允许延迟接受客户端连接,如果为0则表示关闭该功能,如果大于0则表示打开此功能
1630
# 并且此值代表延迟接受连接的超时值,超过此值时如果客户端依然没有发来数据,则操作

examples/grpc/grpc-server.cf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@ service grpc-server {
1010
# 当子进程异常退出时,如果该值非空,则将子进程异常退出的消息通知该服务
1111
# master_notify_addr = 127.0.0.1:5801
1212
# 邮件通知接收者
13-
# master_notify_recipients = [email protected]
13+
# master_notify_recipients = [email protected]
14+
15+
# 停止子进程时是否采用强行停止的方式(即给子进程发送 SIGTERM 信号)
16+
master_stop_kill = false
17+
# 当 master_stop_kill 为 true 时,该配置决定是否要等待子进程退出
18+
master_stop_wait = false
19+
20+
# 当系统支持 SO_REUSEPORT 时,是否启用该功能
21+
master_reuseport = no
22+
# 当启用 SO_REUSEPORT 时(即 master_reuseport=yes 时), 是否需要 acl_master
23+
# 也监听该地址, 对于使用旧版 acl(< 3.5.3-17) 编写的服务, 必须将此项设为
24+
# yes, 即: master_reuseport_listen = yes; 对于使用 acl 版本 >= 3.5.3-17
25+
# 编写的服务需设置为 no; 当 master_reuseport=no时,该项设置将被忽略; 当未
26+
# 设置此项时内部缺省值为 yes. 以便使 acl_master 保持对于旧版服务的兼容性.
27+
master_reuseport_listen = no
1428

1529
# 是否允许延迟接受客户端连接,如果为0则表示关闭该功能,如果大于0则表示打开此功能
1630
# 并且此值代表延迟接受连接的超时值,超过此值时如果客户端依然没有发来数据,则操作

examples/httpd-handler/httpd-handler.cf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@ service httpd-handler {
1010
# 当子进程异常退出时,如果该值非空,则将子进程异常退出的消息通知该服务
1111
# master_notify_addr = 127.0.0.1:5801
1212
# 邮件通知接收者
13-
# master_notify_recipients = [email protected]
13+
# master_notify_recipients = [email protected]
14+
15+
# 停止子进程时是否采用强行停止的方式(即给子进程发送 SIGTERM 信号)
16+
master_stop_kill = false
17+
# 当 master_stop_kill 为 true 时,该配置决定是否要等待子进程退出
18+
master_stop_wait = false
19+
20+
# 当系统支持 SO_REUSEPORT 时,是否启用该功能
21+
master_reuseport = no
22+
# 当启用 SO_REUSEPORT 时(即 master_reuseport=yes 时), 是否需要 acl_master
23+
# 也监听该地址, 对于使用旧版 acl(< 3.5.3-17) 编写的服务, 必须将此项设为
24+
# yes, 即: master_reuseport_listen = yes; 对于使用 acl 版本 >= 3.5.3-17
25+
# 编写的服务需设置为 no; 当 master_reuseport=no时,该项设置将被忽略; 当未
26+
# 设置此项时内部缺省值为 yes. 以便使 acl_master 保持对于旧版服务的兼容性.
27+
master_reuseport_listen = no
1428

1529
# 是否允许延迟接受客户端连接,如果为0则表示关闭该功能,如果大于0则表示打开此功能
1630
# 并且此值代表延迟接受连接的超时值,超过此值时如果客户端依然没有发来数据,则操作

service.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ func GetListenersByAddrs(addrs string) ([]net.Listener, error) {
223223

224224
addrs = strings.Replace(addrs, " ", "", -1)
225225
addrs = strings.Replace(addrs, ",", ";", -1)
226+
addrs = strings.Replace(addrs, "|", ":", -1)
226227
tokens := strings.Split(addrs, ";")
227228

228229
cfg := net.ListenConfig{
@@ -309,7 +310,11 @@ func ServiceInit(addrs string, stopHandler func(bool)) ([]net.Listener, error) {
309310

310311
if !Alone && len(sockType) > 0 {
311312
var err error
312-
listeners, err = GetListeners()
313+
if AppReusePort && len(AppService) > 0 {
314+
listeners, err = GetListenersByAddrs(AppService)
315+
} else {
316+
listeners, err = GetListeners()
317+
}
313318
if err != nil {
314319
log.Println("GetListeners failed", err)
315320
return nil, err

0 commit comments

Comments
 (0)