Skip to content

Commit

Permalink
change md and register npc as a service
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlh committed Dec 16, 2019
1 parent 31af2bb commit eab5708
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 36 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务
- 点击web管理中客户端前的+号,复制启动命令
- 执行启动命令,linux直接执行即可,windows将./npc换成npc.exe用cmd执行

如果需要注册到系统服务可查看[注册到系统服务](https://cnlh.github.io/nps/#/use?id=注册到系统服务)

### 配置
- 客户端连接后,在web中配置对应穿透服务即可
- 更多高级用法见[完整文档](https://cnlh.github.io/nps/)
Expand Down
30 changes: 16 additions & 14 deletions cmd/npc/npc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ var (
target = flag.String("target", "", "p2p target")
localType = flag.String("local_type", "p2p", "p2p target")
logPath = flag.String("log_path", "", "npc log path")
debug = flag.Bool("debug", false, "npc debug")
srv = flag.String("service", "", "service option")
debug = flag.Bool("debug", true, "npc debug")
)

func main() {
Expand Down Expand Up @@ -69,10 +68,15 @@ func main() {
"After=network-online.target syslog.target"}
}
for _, v := range os.Args[1:] {
if !strings.Contains(v, "-service=") {
switch v {
case "install", "start", "stop", "uninstall", "restart":
continue
}
if !strings.Contains(v, "-service=") && !strings.Contains(v, "-debug=") {
svcConfig.Arguments = append(svcConfig.Arguments, v)
}
}
svcConfig.Arguments = append(svcConfig.Arguments, "-debug=false")
prg := &npc{
exit: make(chan struct{}),
}
Expand Down Expand Up @@ -102,19 +106,17 @@ func main() {
}
fmt.Printf("nat type: %s \npublic address: %s\n", nat.String(), host.String())
os.Exit(0)
case "install", "start", "stop", "uninstall", "restart":
if os.Args[1] == "install" {
install.InstallNpc()
}
err := service.Control(s, os.Args[1])
if err != nil {
logs.Error("Valid actions: %q\n", service.ControlAction, err.Error())
}
return
}
}

if *srv != "" {
if *srv == "install" {
install.InstallNpc()
}
err := service.Control(s, *srv)
if err != nil {
logs.Error("Valid actions: %q\n", service.ControlAction, err.Error())
}
return
}
s.Run()
}

Expand Down
2 changes: 2 additions & 0 deletions docs/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
- 点击web管理中客户端前的+号,复制启动命令
- 执行启动命令,linux直接执行即可,windows将./npc换成npc.exe用cmd执行

如果需要注册到系统服务可查看[注册到系统服务](/use?id=注册到系统服务)

## 配置
- 客户端连接后,在web中配置对应穿透服务即可
- 可以查看[使用示例](/example)
53 changes: 31 additions & 22 deletions docs/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,43 @@
## 无配置文件模式
此模式的各种配置在服务端web管理中完成,客户端除运行一条命令外无需任何其他设置
```
./npc -server=ip:port -vkey=web界面中显示的密钥
./npc -debug=true -server=ip:port -vkey=web界面中显示的密钥
```
## 注册到系统服务
对于linux、darwin
- 注册:`sudo ./npc install 其他参数(例如-server=xx -vkey=xx或者-config=xxx)`
- 启动:`sudo ./npc start`
- 停止:`sudo ./npc stop`
- 如果需要更换命令内容需要先卸载`./npc -service=uninstall`,再重新注册

对于windows,使用管理员身份运行cmd

- 注册:`npc.exe install 其他参数(例如-server=xx -vkey=xx或者-config=xxx)`
- 启动:`npc.exe start`
- 停止:`npc.exe stop`
- 如果需要更换命令内容需要先卸载`npc.exe -service=uninstall`,再重新注册

## 客户端更新
首先进入到对于的客户端二进制文件目录

请首先执行`sudo ./npc stop`或者`nps.exe stop`停止运行,然后

对于linux
```shell
sudo ./npc-update update
```
对于windows
```shell
npc-update.exe update
```

更新完成后,执行执行`sudo nps start`或者`nps.exe start`重新运行即可完成升级

## 配置文件模式
此模式使用nps的公钥或者客户端私钥验证,各种配置在客户端完成,同时服务端web也可以进行管理
```
./npc -config=npc配置文件路径
```
可自行添加systemd service,例如:`npc.service`
```
[Unit]
Description=npc - convenient proxy server client
Documentation=https://github.com/cnlh/nps/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=simple
KillMode=process
Restart=always
RestartSec=15s
StandardOutput=append:/var/log/nps/npc.log
ExecStartPre=/bin/echo 'Starting npc'
ExecStopPost=/bin/echo 'Stopping npc'
ExecStart=/absolutely path to/npc -server=ip:port -vkey=web界面中显示的密钥
[Install]
WantedBy=multi-user.target
```
## 配置文件说明
[示例配置文件](https://github.com/cnlh/nps/tree/master/conf/npc.conf)
#### 全局配置
Expand Down

0 comments on commit eab5708

Please sign in to comment.