5

有没有什么方法能让 go 写的命令行程序在 windows 上以服务的方式运行

 3 years ago
source link: https://www.v2ex.com/t/782796
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  程序员

有没有什么方法能让 go 写的命令行程序在 windows 上以服务的方式运行

  darknoll · 48 分钟前 · 525 次点击

以 windows 服务的方式运行,避免误关闭之类的操作

12 条回复    2021-06-11 09:31:30 +08:00

fhy1994

fhy1994   43 分钟前

在 win 上用 nssm 跑过 nginx 、php-cgi 、python 打包的可执行程序

a342191555

a342191555   40 分钟前 via iPhone

github.com/chai2010/winsvc 这个包可以

如果用网络访问的话,记得还要在防火墙添加例外

iminto

iminto   39 分钟前

用自带的 sc create 命令就行,也可以用一些第三方的 wrapper,比如 winsw

catcn

catcn   35 分钟前

2 楼的这个是正解,用过。

chenyi

chenyi   34 分钟前

nssm 用过,可以实现

Rwing

Rwing   31 分钟前

不考虑一下 C#吗,也可以跨平台,独立文件分发,不用运行时。最主要的,可以很爽的用泛型 🙂

zengming00

zengming00   27 分钟前

如果你还玩 nodejs 的话,pm2 是个不错的选择,因为在所有平台都通用
直接一条命令搞定(注意你的程序与参数之间有两个减号)
pm2 start 你的程序 -- 传递给你程序的参数

araraloren

araraloren   21 分钟前

@Rwing 很爽的泛型 哈哈。。

anubu

anubu   7 分钟前

对比过 nssm 和 winsw,nssm 虽然较久没更新,但更好用。最简单的方法是使用 powershell 命令,两三句命令就能搞定,如果不考虑大量程序管理维护的话,是不错的方法。

dream4ever

dream4ever   4 分钟前

@zengming00 PM2 +1,公司买的阿里云服务器装的是 Windows Server 2012,之前解决了 PM2 在注销远程桌面连接后会自动退出的问题后,就彻底省心了,PM2 从几年前用到现在,很方便。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK