Skip to content

Commit

Permalink
custom npc systemd service script, increase open files limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ffdfgdfg committed Jan 22, 2020
1 parent c7a5388 commit 099d3fc
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions cmd/npc/npc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ var (
debug = flag.Bool("debug", true, "npc debug")
)

const systemdScript = `[Unit]
Description={{.Description}}
ConditionFileIsExecutable={{.Path|cmdEscape}}
{{range $i, $dep := .Dependencies}}
{{$dep}} {{end}}
[Service]
LimitNOFILE=65536
StartLimitInterval=5
StartLimitBurst=10
ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}}
{{if .ChRoot}}RootDirectory={{.ChRoot|cmd}}{{end}}
{{if .WorkingDirectory}}WorkingDirectory={{.WorkingDirectory|cmdEscape}}{{end}}
{{if .UserName}}User={{.UserName}}{{end}}
{{if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{end}}
{{if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{end}}
{{if and .LogOutput .HasOutputFileSupport -}}
StandardOutput=file:/var/log/{{.Name}}.out
StandardError=file:/var/log/{{.Name}}.err
{{- end}}
Restart=always
RestartSec=120
[Install]
WantedBy=multi-user.target
`

func main() {
flag.Parse()
logs.Reset()
Expand All @@ -54,8 +79,6 @@ func main() {

// init service
options := make(service.KeyValue)
options["Restart"] = "on-success"
options["SuccessExitStatus"] = "1 2 8 SIGKILL"
svcConfig := &service.Config{
Name: "Npc",
DisplayName: "nps内网穿透客户端",
Expand All @@ -66,6 +89,7 @@ func main() {
svcConfig.Dependencies = []string{
"Requires=network.target",
"After=network-online.target syslog.target"}
svcConfig.Option["SystemdScript"] = systemdScript
}
for _, v := range os.Args[1:] {
switch v {
Expand Down

0 comments on commit 099d3fc

Please sign in to comment.