src/services/service.ts   A
last analyzed

Complexity

Total Complexity 11
Complexity/F 1.57

Size

Lines of Code 39
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 34
mnd 4
bc 4
fnc 7
dl 0
loc 39
rs 10
bpm 0.5714
cpm 1.5713
noi 0
c 0
b 0
f 0

7 Functions

Rating   Name   Duplication   Size   Complexity  
A Service.reload 0 4 2
A Service.stop 0 4 2
A Service.start 0 4 2
A Service.install 0 2 1
A Service.restart 0 4 2
A Service.configure 0 2 1
A Service.uninstall 0 2 1
1
import OS from '../client/OS'
2
3
abstract class Service {
4
    abstract service: string
5
    requireRoot = false
6
7
    start = async (): Promise<boolean> =>
8
        this.requireRoot ?
9
            OS.getInstance().serviceCtl.startAsRoot(this.service) :
10
            OS.getInstance().serviceCtl.start(this.service)
11
12
    stop = async (): Promise<boolean> =>
13
        this.requireRoot ?
14
            OS.getInstance().serviceCtl.stopAsRoot(this.service) :
15
            OS.getInstance().serviceCtl.stop(this.service)
16
17
    restart = async (): Promise<boolean> =>
18
        this.requireRoot ?
19
            OS.getInstance().serviceCtl.restartAsRoot(this.service) :
20
            OS.getInstance().serviceCtl.restart(this.service)
21
22
    reload = async (): Promise<boolean> =>
23
        this.requireRoot ?
24
            OS.getInstance().serviceCtl.reloadAsRoot(this.service) :
25
            OS.getInstance().serviceCtl.reload(this.service)
26
27
    install = (): Promise<boolean> => {
28
        return OS.getInstance().packageManager.install(this.service, false)
29
    }
30
31
    uninstall = (): Promise<boolean> => {
32
        return OS.getInstance().packageManager.uninstall(this.service, false)
33
    }
34
35
    abstract configure(): Promise<boolean>
36
}
37
38
export default Service
39