Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svc test-worker 可以成功执行程序,svc install 无法执行程序。 #21

Open
Southseast opened this issue Mar 14, 2023 · 13 comments

Comments

@Southseast
Copy link

Southseast commented Mar 14, 2023

想部署个 npc 连 nps 的。

(base) PS D:\npc_service> svc test-worker
[svc.info] Created Worker `npc.exe` in `D:\npc_service\worker`
2023/03/14 20:59:24.243 [I] [npc.go:231]  the version of client is 0.26.10, the core version of client is 0.26.0
2023/03/14 20:59:24.248 [I] [control.go:97]  Loading configuration file D:\npc_service\worker\conf\npc.conf successfully
2023/03/14 20:59:24.289 [N] [control.go:176]  web access login username:x password:x
2023/03/14 20:59:24.318 [I] [client.go:72]  Successful connection with server ip:port
(base) PS D:\npc_service> svc install
Installed Service "npc-service"
Started Service "npc-service"

然后 svc.log 里给的是:

[2023-03-14 20:59:37] [INFO] Installed Service "npc-service"
[2023-03-14 20:59:37] [INFO] 
[2023-03-14 20:59:37] [INFO] Created Worker `npc.exe` in `D:\npc_service\worker`
[2023-03-14 20:59:37] [WARN] The worker exited without be notified, it will be re-created after 5 seconds
[2023-03-14 20:59:42] [INFO] Created Worker `npc.exe` in `D:\npc_service\worker`
[2023-03-14 20:59:43] [WARN] The worker exited without be notified, it will be re-created after 5 seconds
[2023-03-14 20:59:48] [INFO] Created Worker `npc.exe` in `D:\npc_service\worker`
[2023-03-14 20:59:49] [WARN] The worker exited without be notified, it will be re-created after 5 seconds
[2023-03-14 20:59:54] [INFO] Created Worker `npc.exe` in `D:\npc_service\worker`
[2023-03-14 20:59:55] [WARN] The worker exited without be notified, it will be re-created after 5 seconds
[2023-03-14 21:00:00] [INFO] Created Worker `npc.exe` in `D:\npc_service\worker`
[2023-03-14 21:00:01] [WARN] The worker exited without be notified, it will be re-created after 5 seconds
@pandolia
Copy link
Owner

配置文件里面指定一下 User 和 Password 再试试吧

@pandolia
Copy link
Owner

可能是 LocalSystem 用户没有权限连接外部网络。

@wy16W2pIilK1xgqN
Copy link

我也遇到了,同样的问题。
我只是用一个启动 MPV 播放本地视频的简单程序,不需要联网。
如果指定密码就会报错。

Installed Service "mpv_paly-svc"
Starting service "mpv_paly-svc"...
未经处理的异常:  System.InvalidOperationException: 无法启动计算机“.”上的服务 mpv_paly-svc。 ---> System.ComponentModel.Win32Exception: 由于登录失败而无法启动服务。
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.ServiceProcess.ServiceController.Start(String[] args)
   在 SvcUtils.StartSvc(ServiceController sc)
   在 Libs.Timeout(Action f, Int32 seconds, String startMsg, String timeoutMsg, String okMsg)
   在 SvcUtils.StartService(ServiceController sc)
   在 Program.ManageOneByConfFile(String op)
   在 Program.Main(String[] args)

@pandolia
Copy link
Owner

如果使用普通用户运行服务,需要先授予这个用户运行服务的权限,具体步骤为:

  1. 先不填 Domain, User, Password 这三项,服务安装完成后,在Windows系统的“服务”管理列表里面,双击那个服务,弹出服务属性对话框,在“登录”选项卡里,填入用户名、密码,再点应用。最后启动服务。

1

2

  1. 如果能正常启动,再填上 Domain, User, Password 。

@wy16W2pIilK1xgqN
Copy link

wy16W2pIilK1xgqN commented Oct 27, 2023

谢谢回复,但 我尝试了一下,还是不行。
总结一下目前的状态。
svc.exe test-worker .\mpv_paly-svc\ #启动正常。
svc.exe install .\mpv_paly-svc\ #无法启动
在系统 服务管理中指定密码,还是无法启动
操作系统
win11 22H2 22621.2428

PS D:\easy-service-master\bin> .\svc.exe check .\mpv_paly-svc\
ServiceName: mpv_paly-svc
DisplayName: mpv_paly-svc
Description: An example of EasyService
Dependencies:
Worker: mpv.exe  --no-config    --no-audio --loop-file=inf  --hwdec=yes -fs  "D:\123.mp4"
Worker's fileName: D:\mpv-0.34.0-x86_64\mpv.exe
Worker's arguments: --no-config    --no-audio --loop-file=inf  --hwdec=yes -fs  "D:\123.mp4"
Worker's enrinonments: [TEST-ENV1]=[A1], [TEST-ENV2]=[A2], [TEST-ENV3]=[A3], [TEST-ENV4]=[A4], [TEST-ENV5]=[A5], [TEST-ENV6]=[A6]
WorkingDir: D:\mpv-0.34.0-x86_64
OutFileDir:
WaitSecondsForWorkerToExit: 5
MaxLogFilesNum:  (WARN: This property is deprecated since v1.0.11)
WorkerEncoding: null
WorkerMemoryLimit: -1
Domain: .
User:
Password:

@pandolia
Copy link
Owner

在服务管理器里面启动服务也不行么?

@wy16W2pIilK1xgqN
Copy link

在服务管理器里面启动服务也不行么?

是的

@pandolia
Copy link
Owner

这个程序是不是要打开一个视频文件播放?
服务程序好像不能和GUI桌面交互。

@pandolia
Copy link
Owner

只能是后台console程序。

@wy16W2pIilK1xgqN
Copy link

只能是后台console程序。

看来是这个问题了,谢谢答复。

@pandolia
Copy link
Owner

不客气。也可以试试windows的定时任务,下面的 powershell 脚本可以注册一个定时任务,每天3点运行一下main.ps1

$action = New-ScheduledTaskAction -Execute powershell.exe -Argument "`"D:\main.ps1`""

$trigger = New-ScheduledTaskTrigger -Daily -At "3:00"

Register-ScheduledTask -TaskName "my-task" `
    -Description "my-scheduled-task" `
    -User "$env:USERDOMAIN\$env:USERNAME" `
    -Password "$systemPassword" `
    -Action $action `
    -Trigger $trigger

@wy16W2pIilK1xgqN
Copy link

不客气。也可以试试windows的定时任务,下面的 powershell 脚本可以注册一个定时任务,每天3点运行一下main.ps1

$action = New-ScheduledTaskAction -Execute powershell.exe -Argument "`"D:\main.ps1`""

$trigger = New-ScheduledTaskTrigger -Daily -At "3:00"

Register-ScheduledTask -TaskName "my-task" `
    -Description "my-scheduled-task" `
    -User "$env:USERDOMAIN\$env:USERNAME" `
    -Password "$systemPassword" `
    -Action $action `
    -Trigger $trigger

这也是个办法,谢谢指点。😉

@zhuangdx
Copy link

zhuangdx commented Jan 2, 2024

npc也是这个问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants