@remote.it/core
Version:
Core remote.it JavasScript/TypeScript library
110 lines (99 loc) • 2.51 kB
text/typescript
import debug from 'debug'
import { GenericSystemService } from './GenericSystemService'
import { WinSW } from './WinSW'
import { Environment } from './Environment'
import { XMLFile } from './XMLFile'
const d = debug('remoteit:WindowsSystemService')
interface WinSWFile {
configuration: {
id: {
text: string
}
name: {
text: string
}
description?: {
text: string
}
executable: {
text: string
}
arguments?: {
text: string
}
priority?: { text: string }
stoptimeout?: {
text: string
}
stopparentprocessfirst?: {
text: boolean
}
startmode?: { text: 'Automatic' | 'Manual' | 'Boot' | 'System' }
waithint?: { text: string }
sleeptime?: { text: string }
log?: {
attributes: {
mode: 'append' | 'none' | 'reset' | 'roll' | 'roll-by-time' | 'rotate'
}
}
}
}
export class WindowsSystemService extends GenericSystemService {
name: string = 'remote.it System Service'
private winsw: WinSW
private winswFile: XMLFile<WinSWFile>
constructor(public config: string = Environment.configPath) {
super(config)
this.winswFile = new XMLFile<WinSWFile>(Environment.winswXMLPath)
this.winsw = new WinSW(this.winswFile)
}
async install() {
d('Installing service:', this.command)
// if (this.exists) this.uninstall()
this.createWinSWXMLFile()
await this.winsw.install()
d('post winsw install')
return this
}
async start() {
if (!this.exists) await this.install()
await this.winsw.start()
return this
}
async stop() {
await this.winsw.stop()
return this
}
async uninstall() {
d('Uninstalling service')
await this.winsw.stop()
await this.winsw.uninstall()
this.winswFile.remove()
return this
}
get exists() {
return this.winswFile.exists
}
private createWinSWXMLFile() {
d('writing winsw.xml file:', this.winswFile.location)
this.winswFile.write({
configuration: {
name: {
text: 'remote.it System Service',
},
id: { text: 'it.remote.core' },
description: {
text:
'remote.it System Service that ensures your connections stay running',
},
executable: { text: Environment.remoteitPath },
arguments: { text: `watch -c ${Environment.configPath}` },
// log: {
// attributes: {
// mode: 'roll',
// },
// },
},
})
}
}