zap日志写入通道被覆盖
golang离线环境依赖包问题

nats-server系统服务只能使用sc命令注册

妙音 posted @ 2021年8月19日 02:42 in golang with tags nats , 339 阅读
 

起因描述

 
windows环境下nats-server注册成系统, 官方推荐是sc命令
 
而我觉得sc命令台太麻烦, 为什么不用github.com/kardianos/service,或者更方便的工具呢?
 

方法一:使用nssm通过界面进行配置

 
1. 下载地址
 
http://nssm.cc/download
 
2. 过程省略
 
3. 结果死活不行,由于是第三方工具,出错找不到原因,放弃
 
 

方法二:通过服务外壳作为系统服务

 
* 介绍
 
使用go生成一个demo.exe,再将demo.exe注册成系统,demo.exe读取配置文件,然后demo.exe通过exec.Command启动nats-server.exe
 
go比较好用的库可以用github.com/kardianos/service
 
 
* demo.exe启动nats-server.exe关键源码
 
p.cmd = exec.Command(fullExec, p.Args...)
p.cmd.Dir = p.Dir
p.cmd.Env = append(os.Environ(), p.Env...)
 
* demo.json配置示例
 
{
"Name": "demo",
"DisplayName": "demo",
"Description": "demo for nats-server",

"Dir": "d:\\nats-server",
"Exec": "xxxx\\nats-server.exe",
"Args": ["-c ","xxx\\nats-server.conf"],
"Env": [
],

"Stderr": "C:\\log\\nats_err.log",
"Stdout": "C:\\log\\nats_out.log"
}
 
* 结果报错
 
The service process could not connect to the service controller.
 
意思是一个服务不能连接到另一个服务,啥意思呢? 也就是通过exec.Command启动的竟然是服务,不应该是exe么.
 
* nats-server启动源码分析
 
nats-server.exe的启动入口源码
 
func Run(server *Server) error {
    //入口1:docker
if dockerized {
server.Start()
return nil
}
isInteractive, err := svc.IsAnInteractiveSession()
if err != nil {
return err
}
    //入口2: 交互模式
if isInteractive {
server.Start()
return nil
}
    //入口3: 启动服务(serviceName被写死了,只能是nats-server)
return svc.Run(serviceName, &winServiceWrapper{server})
}
 
* 错误原因总结
 
当以外壳方式启动时,走的是"入口3",也是启动服务,如果没有nats-server,它就啥事也没干,结果nats-server并没有启动
 

方法三:sc命令

 
官方推荐
 

总结

 
1、nat-server只能以sc命令注册成服务。怕麻烦可以写一个bat。
 
2、nats-server服务名只能是nats-server
 
 
Avatar_small
danske casino 说:
2021年8月21日 23:24

That is why a good idea is you need to connected examine prior to producing. You can actually distribute greater distribute this way.

Avatar_small
https://ccurlrebondi 说:
2021年8月25日 00:47

Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. https://ccurlrebonding74.shutterfly.com/21

Avatar_small
video alarm singapor 说:
2021年8月26日 13:55

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work video alarm singapore

Avatar_small
best cake delivery s 说:
2021年9月01日 15:25

Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. best cake delivery singapore

Avatar_small
AAA 说:
2021年9月03日 00:29

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! магазин интернет магазин

Avatar_small
dfg` 说:
2021年9月04日 23:54

This article is an appealing wealth of informative data that is interesting and well-written. I commend your hard work on this and thank you for this information. You’ve got what it takes to get attention. oreotv

Avatar_small
how to sell merchant 说:
2021年9月05日 16:51

Great Information sharing .. I am very happy to read this article .. thanks for giving us go through info.Fantastic nice. I appreciate this post. how to sell merchant services

Avatar_small
dfg` 说:
2021年9月11日 18:41

This is my first time visit here. From the tons of comments on your articles,I guess I am not only one having all the enjoyment right here! lions breath carts

Avatar_small
dfg` 说:
2021年9月12日 22:08

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post. https://barowatt.com

Avatar_small
dfg` 说:
2021年9月13日 19:06

Awesome and interesting article. Great things you've always shared with us. Thanks. Just continue composing this kind of post. free bigfish slots

Avatar_small
dfg` 说:
2021年9月13日 23:06

It is truly a well-researched content and excellent wording. I got so engaged in this material that I couldn’t wait reading. I am impressed with your work and skill. Thanks. pubg name generator

Avatar_small
dfg` 说:
2021年9月17日 15:39

I really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good.Thanks alot! Star Network Referral Code

Avatar_small
Hardik 说:
2021年9月17日 17:43

I’m impressed, I must say. Truly rarely must i encounter a weblog that’s both educative and entertaining, and without a doubt, you have hit the nail about the head. Your concept is outstanding; the thing is something too few people are speaking intelligently about. My business is happy that we stumbled across this within my search for some thing relating to this.

Avatar_small
먹튀검증 说:
2021年9月18日 14:59

If you are looking for more information about flat rate locksmith Las Vegas check that right away. 먹튀검증

Avatar_small
dfg` 说:
2021年9月21日 22:30

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. blackpods

Avatar_small
dfg` 说:
2021年9月24日 15:06

Recently, I have commenced a blog the info you give on this site has encouraged and benefited me hugely. Thanks for all of your time & work. buy organic seeds

Avatar_small
dfg` 说:
2021年9月25日 00:34

Dengue fever is another mosquito-borne deadly disease mostly finds in tropical areas. A huge number of people from India, Southeast Asia, China, the Caribbean island, and African tested Dengue Symptoms every year.

Avatar_small
Online pharmacy stor 说:
2021年9月26日 19:02

Visit Lavi Pharmacy for a Wide Range of Quality Pharmaceutical Products. Contact Lavi Pharmacy for Affordable Pharmaceutical Products Today. Online pharmacy store Port Harcourt

Avatar_small
dfg` 说:
2021年9月27日 00:16

I have read all the comments and suggestions posted by the visitors for this article are very fine,We will wait for your next article so only.Thanks! Sofa cleaning Waterlooville

Avatar_small
dfg` 说:
2021年9月27日 17:52

Thanks for the blog filled with so many information. Stopping by your blog helped me to get what I was looking for. Now my task has become as easy as ABC. poker

Avatar_small
liga228 说:
2021年9月27日 18:20

Since it finds distinctive internet betting locales, it is exceptionally difficult for them to flee, assuming they perpetrate violations. liga228

Avatar_small
dfg` 说:
2021年9月28日 00:26

Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging.. moving-local-distance-to-austin

Avatar_small
dfg` 说:
2021年9月28日 00:37

Just admiring your work and wondering how you managed this blog so well. It’s so remarkable that I can't afford to not go through this valuable information whenever I surf the internet! Packing Tips: The Complete List of Dos And Don’ts For Long-Distance Moving

Avatar_small
dfg` 说:
2021年9月28日 00:57

You have a good point here!I totally agree with what you have said!!Thanks for sharing your views...hope more people will read this article!!! What Is the Average Cost of Moving an Apartment?

Avatar_small
dfg` 说:
2021年9月28日 18:09

In the world of www, there are countless blogs. But believe me, this blog has all the perfection that makes it unique in all. I will be back again and again. City top lawyer

Avatar_small
huram 说:
2021年9月28日 22:50

You possess lifted an essential offspring..Blesss for using..I would want to study better latest transactions from this blog..preserve posting.. <a href="https://www.thenewcanadians.com/?fbclid=IwAR3_6ZAviXa01yzNp94ajApHUvZANDZL3ENoZO1NTM26P0DbmDHzOqTs7eg">situs idn poker</a>

Avatar_small
exam dumps 说:
2021年9月29日 01:10

We are offering genuine pdf dumps with real pdf questions. Certsquestions offer the most recent and 100% updated prepration material for the Prepration of Certifications Exams. exam dumps

Avatar_small
fiserv agent program 说:
2021年10月01日 14:12

This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you. fiserv agent program

Avatar_small
merchant processing 说:
2021年10月01日 16:43

I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. merchant processing iso program

Avatar_small
start your own credi 说:
2021年10月01日 18:47

Good post but I was wondering if you could write a litte more on this subject? I’d be very thankful if you could elaborate a little bit further. Appreciate it! start your own credit card processing company

Avatar_small
Starting a payment p 说:
2021年10月02日 13:00

Efficiently written information. It will be profitable to anybody who utilizes it, counting me. Keep up the good work. For certain I will review out more posts day in and day out. Starting a payment processing company

Avatar_small
become a payment pro 说:
2021年10月03日 14:43

Thanks for taking the time to discuss this, I feel strongly that love and read more on this topic. If possible, such as gain knowledge, would you mind updating your blog with additional information? It is very useful for me. become a payment processor

Avatar_small
merchant services sa 说:
2021年10月03日 18:00

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post. merchant services sales

Avatar_small
dfg` 说:
2021年10月07日 15:07

I got too much interesting stuff on your blog. I guess I am not the only one having all the enjoyment here! Keep up the good work. open source real estate crowdfunding software

Avatar_small
dfg` 说:
2021年10月10日 22:03

Thanks so much for sharing this awesome info! I am looking forward to see more postsby you! endreinigung

Avatar_small
dfg` 说:
2021年10月12日 18:02 I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. 먹튀폴리스
Avatar_small
dfg` 说:
2021年10月14日 13:56

A great content material as well as great layout. Your website deserves all of the positive feedback it’s been getting. I will be back soon for further quality contents. Latest rap news

Avatar_small
dfg` 说:
2021年10月14日 15:54

Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. lottery

Avatar_small
Dr.Billa 说:
2021年10月18日 04:52

Great work✅ This is the type of information that should be shared around the web. I also have some information related to on my website✅ emirates flights


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter