-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7f58834
Showing
6 changed files
with
402 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## Servicio Consola | ||
|
||
Crea un servicio de windows mediante la consola | ||
|
||
|
||
### install | ||
Instala e inicia un nuevo servicio | ||
|
||
``` | ||
service install -n "Mi Servicio" -d "Mi Descripcion" -s RutaDeScript | ||
``` | ||
|
||
#### Parámetros | ||
* --name, -n Service name [string] [required] | ||
* --description, -d Service short desc [string] | ||
* --script, -s Script path [string] [required] | ||
|
||
|
||
|
||
### uninstall | ||
Desintala un servicio existente | ||
|
||
``` | ||
service uninstall -n "Mi Servicio" -s RutaDeScript | ||
``` | ||
|
||
#### Parámetros | ||
* --name, -n Service name [string] [required] | ||
* --script, -s Script path [string] [required] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "servicio-consola", | ||
"version": "1.0.0", | ||
"description": "Crea servicios de windows", | ||
"main": "app.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/bibiwatson/servicio-windows.git" | ||
}, | ||
"author": "Emma Colorado", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/bibiwatson/servicio-windows/issues" | ||
}, | ||
"homepage": "https://github.com/bibiwatson/servicio-windows#readme", | ||
"dependencies": { | ||
"colors": "^1.4.0", | ||
"readline": "^1.3.0", | ||
"yargs": "^15.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { argv } = require('./yargs.js'); | ||
const { CustomService } = require('./service/CustomService'); | ||
const wincmd = require('node-windows'); | ||
|
||
|
||
const command = argv._[0]; | ||
|
||
switch(command){ | ||
case 'install': | ||
new CustomService({ | ||
name : argv.name, | ||
description : argv.description || '', | ||
script : argv.script || '' | ||
}).install(); | ||
break; | ||
|
||
case 'uninstall': | ||
new CustomService({ | ||
name : argv.name, | ||
script : argv.script || '' | ||
}).uninstall(); | ||
break; | ||
|
||
default: | ||
console.log('Command not accepted'); | ||
break; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const Service = require('node-windows').Service; | ||
const colors = require('colors'); | ||
const EventLogger = require('node-windows').EventLogger; | ||
|
||
class CustomService { | ||
constructor(data){ | ||
this.name = data.name; | ||
this.description = data.description || ''; | ||
this.script = data.script; | ||
|
||
this.log = new EventLogger(''); | ||
|
||
return this; | ||
} | ||
|
||
install() { | ||
this.svc = new Service({ | ||
name : this.name, | ||
description : this.description, | ||
script : this.script | ||
}); | ||
|
||
this.listen(); | ||
this.svc.install(); | ||
} | ||
|
||
uninstall() { | ||
this.svc = new Service({ | ||
name : this.name, | ||
script : this.script | ||
}); | ||
|
||
this.listen(); | ||
this.svc.uninstall(); | ||
} | ||
|
||
listen(){ | ||
this.svc.on('install', () => { | ||
console.log('Service is installed'.green); | ||
console.log('Starting service ...'.yellow); | ||
|
||
this.svc.start(); | ||
}); | ||
|
||
this.svc.on('alreadyinstalled', () => { | ||
console.log('Service is alreadyinstalled'.yellow) | ||
}); | ||
|
||
this.svc.on('invalidinstallation', () => { | ||
console.log('Invalid Instalation'.red); | ||
}) | ||
|
||
this.svc.on('uninstall', () => { | ||
console.log('Service has been uninstalled'.green); | ||
}) | ||
|
||
this.svc.on('start', () => { | ||
console.log('Service is running'.green); | ||
}); | ||
|
||
this.svc.on('stop', () => { | ||
console.log('Service has stopped'.yellow); | ||
}); | ||
|
||
this.svc.on('error', function(err){ | ||
this.log.error(err || 'Something went wrong'); | ||
}) | ||
} | ||
} | ||
|
||
module.exports = { | ||
CustomService | ||
} |
Oops, something went wrong.