jaredly / hexo-admin

An Admin Interface for Hexo
http://jaredly.github.io/hexo-admin/
1.77k stars 299 forks source link

deploy Error: spawn UNKNOWN #94

Closed xbotao closed 7 years ago

xbotao commented 7 years ago

I follow #70 to do. But there is an error when I click the 'Deploy' button. Error is "Error: spawn UNKNOWN"


I use windows and firefox brower.

pirtleshell commented 7 years ago

Does hexo deploy function as expected when run from the command line?

xbotao commented 7 years ago

The command hexo deploy is OK when run from the comamnd line.

xbotao commented 7 years ago

Error Info

INFO  Start processing
INFO  Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.
EEE { Error: spawn UNKNOWN
    at exports._errnoException (util.js:953:11)
    at ChildProcess.spawn (internal/child_process.js:302:11)
    at exports.spawn (child_process.js:372:9)
    at module.exports (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\hexo-admin\deploy.js:14:14)
    at E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\hexo-admin\api.js:265:7
    at E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\hexo-admin\api.js:91:7
    at call (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:239:7)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:183:5)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at next (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\connect\index.js:161:14)
    at E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\body-parser\lib\read.js:129:5
    at invokeCallback (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\raw-body\index.js:262:16)
    at done (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\raw-body\index.js:251:7)
    at IncomingMessage.onEnd (E:\WorkSpace\webProject\Hexo-oschina\blog\node_modules\raw-body\index.js:307:7)
    at emitNone (events.js:86:13)
    at IncomingMessage.emit (events.js:185:7) code: 'UNKNOWN', errno: 'UNKNOWN', syscall: 'spawn' }
pirtleshell commented 7 years ago

Deploy uses child_process to run your deploy command. It looks like the UNKNOWN errors occur either from permissions issues (this stackoverflow question) or from how Windows doesn't support shebangs to directly run files (https://github.com/babel/babili/issues/108#issuecomment-242938483).

What is the admin.deployCommand of your _config.yml? Try running the command directly in the terminal. Does it deploy correctly?

xbotao commented 7 years ago

Running the command directly in the terminal is correctly. qq 20170102104526

admin:
  deployCommand: './hexo-deploy.sh'

and I try it on the ubuntu, it's OK. I think windows doesn't support it.

pirtleshell commented 7 years ago

I think it's a permissions or shebang problem like from the posts mentioned above. You'll just have to play around with it to get it to work with Windows.

What are the contents of hexo-deploy.sh?

Does deploying work when you start hexo with administrative privileges (sudo hexo server)?

If that doesn't work, try setting deployCommand to the following and see if either of them work:

xbotao commented 7 years ago

The contents of hexo-deploy.sh

#!/usr/bin/env sh
hexo g && hexo d

$ sudo hexo s -d
bash: sudo: command not found

admin:
  deployCommand: 'hexo deploy'

error log

res { Error: spawn hexo deploy ENOENT
    at exports._errnoException (util.js:953:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
    at onErrorNT (internal/child_process.js:348:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn hexo deploy',
  path: 'hexo deploy',
  spawnargs: [ '' ] } { stdout: '', stderr: '' }

admin:
  deployCommand: 'sh hexo-deploy.sh'

error log

res { Error: spawn sh hexo-deploy.sh ENOENT
    at exports._errnoException (util.js:953:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
    at onErrorNT (internal/child_process.js:348:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn sh hexo-deploy.sh',
  path: 'sh hexo-deploy.sh',
  spawnargs: [ '' ] } { stdout: '', stderr: '' }

admin:
  deployCommand: 'node ./node_modules/hexo/bin/hexo deploy'

error log

res { Error: spawn node ./node_modules/hexo/bin/hexo deploy ENOENT
    at exports._errnoException (util.js:953:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
    at onErrorNT (internal/child_process.js:348:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn node ./node_modules/hexo/bin/hexo deploy',
  path: 'node ./node_modules/hexo/bin/hexo deploy',
  spawnargs: [ '' ] } { stdout: '', stderr: '' }
xbotao commented 7 years ago

I found a compromise method to deploy blog by click the deploy button.

create a hexo-deploy.bat file

hexo d

and set the deployCommand to deployCommand: 'hexo-deploy.bat' But a cmd console will pop when click the deploy button.

xbotao commented 7 years ago

Accoding to this issue(Using nodejs's spawn causes “unknown option — ” and “[Error: spawn ENOENT]” errors) I change //var proc = spawn(command, [message], {detached: true}); to var proc = spawn((process.platform === "win32" ? "hexo.cmd" : "hexo"), ['d']);

It works! Thanks for your patiently reply.

xbotao commented 7 years ago

sorry, just spawn((process.platform === "win32" ? "hexo.cmd" : "hexo"), ['d']); is not correctly.

need generate before hexo d

var proc = spawn((process.platform === "win32" ? "hexo.cmd" : "hexo"), ['d', '-g']);
xbotao commented 7 years ago

what I alter.And I test it on win10 and ubuntu. api.js deploy.js#L13 deploy.js#L16

xbotao commented 7 years ago

Could you test this code and pull it? @PirtleShell

pirtleshell commented 7 years ago

This is good to know, but the idea of deployCommand is that many things can be run on deployment, not just hexo d -g. I think limiting deployment to just this one command would be a regression. Did you try setting hexo.cmd d -g as your deployCommand in _config.yml?

The batch file also worked for you, so I think the current functionality is good. This is a great thread for someone who has problems with deploying on windows in the future though! Thanks for the thorough explanation!

xbotao commented 7 years ago

Got it.I think you mean,the current functionality cloud run any command you want rather than hexo g.

pirtleshell commented 7 years ago

That's right :smile: And it works on windows given the right command.

xbotao commented 7 years ago

Accoding to the exec function define

 if (process.platform === 'win32') {
file = 'cmd.exe';
args = ['/s', '/c', '"' + command + '"'];
// Make a shallow copy before patching so we don't clobber the user's
// options object.
options = util._extend({}, options);
options.windowsVerbatimArguments = true;
} else {
  file = '/bin/sh';
  args = ['-c', command];
}

I think this can do like this on windows: create a .bat file, content is

hexo deploy

and the deploy.js code is

  var proc;
  if(process.platform === "win32"){
    proc =  exec('hexo-deploy.bat');
  }else{
    proc = spawn(command, [message], {detached: true});
  }

the result is: qq 20170105094715


There is a disadvantage of exec command, the options' maxBuffer is limited to 200k. But I think 200K is enough in this enviroment.