ubuntu-service 0.0.0-stage β 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +116 -2
- package/bin/index.js +8 -0
- package/package.json +45 -3
- package/src/cli.js +2 -0
- package/src/index.js +3 -0
- package/src/v1/actions.js +58 -0
- package/src/v1/cli.js +245 -0
- package/src/v1/detector.js +194 -0
- package/src/v1/index.js +55 -0
- package/src/v1/parser.js +113 -0
- package/src/v1/systemctl.js +147 -0
- package/src/v2/actions.js +58 -0
- package/src/v2/cli.js +245 -0
- package/src/v2/detector.js +195 -0
- package/src/v2/index.js +55 -0
- package/src/v2/parser.js +113 -0
- package/src/v2/systemctl.js +147 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 KeshavSoft
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,117 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ubuntu-service
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/ubuntu-service)
|
|
4
|
+
[](https://opensource.org/licenses/ISC)
|
|
5
|
+
[](https://github.com/keshavsoft)
|
|
6
|
+
[](https://nodejs.org)
|
|
7
|
+
[](https://github.com/keshavsoft/ubuntu-service)
|
|
8
|
+
|
|
9
|
+
> **Context-aware single service manager for Ubuntu VPS.**
|
|
10
|
+
> Automatically identifies the systemd service associated with your current working directory (`process.cwd()`), inspects its status, restarts it, and displays its logs. Zero memory neededβrun right after `git pull`.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## π― The Philosophy: Singular vs. Plural
|
|
15
|
+
|
|
16
|
+
| Repository | Focus | Scope | Question Answered |
|
|
17
|
+
| :--- | :--- | :--- | :--- |
|
|
18
|
+
| **`ubuntu-services`** *(Plural)* | Fleet / Inventory | All services on the OS | *"What is everything running on my Ubuntu VPS? Are there broken folders?"* |
|
|
19
|
+
| **`ubuntu-service`** *(Singular)* | Atomic / Current App | Single service for current directory | *"What service runs THIS folder, and let me restart only this service right now."* |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## π‘ The Everyday VPS Problem
|
|
24
|
+
|
|
25
|
+
When deploying code on an Ubuntu server:
|
|
26
|
+
```bash
|
|
27
|
+
root@server6358:~/KeshavSoft/appointment-notifier# git pull
|
|
28
|
+
Updating cced23f..34bc3e5
|
|
29
|
+
Fast-forward
|
|
30
|
+
...
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Now you need to restart the application. But:
|
|
34
|
+
* *What is the exact systemd unit name for this directory?*
|
|
35
|
+
* Is it `appointment.service`? `appointment-notifier.service`? `appointment.keshavsoft.com.service`?
|
|
36
|
+
* Instead of grepping `/etc/systemd/system/` or rebooting the server:
|
|
37
|
+
|
|
38
|
+
Simply run:
|
|
39
|
+
```bash
|
|
40
|
+
us restart
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## β‘ Quick Start
|
|
46
|
+
|
|
47
|
+
Run directly with zero installation via `npx`:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Stand in any project directory on your Ubuntu VPS
|
|
51
|
+
cd /root/KeshavSoft/appointment-notifier
|
|
52
|
+
|
|
53
|
+
# 1. Inspect the service running this directory
|
|
54
|
+
npx ubuntu-service
|
|
55
|
+
# Or with short alias:
|
|
56
|
+
us
|
|
57
|
+
|
|
58
|
+
# 2. Restart ONLY this service
|
|
59
|
+
us restart
|
|
60
|
+
|
|
61
|
+
# 3. View live systemd logs
|
|
62
|
+
us logs -n 50
|
|
63
|
+
|
|
64
|
+
# 4. Output only the unit name (e.g. for scripts or CI)
|
|
65
|
+
us name
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## π CLI Commands
|
|
71
|
+
|
|
72
|
+
| Command | Description |
|
|
73
|
+
| :--- | :--- |
|
|
74
|
+
| `us` / `npx ubuntu-service` | Shows service card: unit name, state, PID, memory, port, working directory |
|
|
75
|
+
| `us restart` | Restarts only the service attached to the current directory and verifies status |
|
|
76
|
+
| `us status` | Detailed status inspection for the current service |
|
|
77
|
+
| `us logs [-n <count>]` | Fetches live `journalctl` logs for this specific service |
|
|
78
|
+
| `us name` | Prints only the unit name (e.g. `appointment.keshavsoft.com.service`) |
|
|
79
|
+
| `us port` | Prints only the detected port (e.g. `3000`) |
|
|
80
|
+
|
|
81
|
+
### Flags & Options
|
|
82
|
+
|
|
83
|
+
* `--dir <path>`: Target a specific folder instead of `process.cwd()`
|
|
84
|
+
* `--systemd-dir <path>`: Custom systemd directory (useful for testing)
|
|
85
|
+
* `-n, --lines <count>`: Number of log lines to retrieve (default: 25)
|
|
86
|
+
* `--json`: Output machine-readable JSON
|
|
87
|
+
* `-h, --help`: Display help screen
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## ποΈ Architecture
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
ubuntu-service/
|
|
95
|
+
βββ bin/
|
|
96
|
+
β βββ index.js # Executable entrypoint (`ubuntu-service`, `us`)
|
|
97
|
+
βββ src/
|
|
98
|
+
β βββ index.js # Orchestrator (delegates to latest v1)
|
|
99
|
+
β βββ cli.js # CLI Orchestrator
|
|
100
|
+
β βββ v1/
|
|
101
|
+
β βββ index.js # Public API exports
|
|
102
|
+
β βββ detector.js # Context detection (CWD to systemd unit mapping)
|
|
103
|
+
β βββ parser.js # Systemd .service INI & port parser
|
|
104
|
+
β βββ systemctl.js # Native systemctl & journalctl execution
|
|
105
|
+
β βββ actions.js # Business actions (inspect, restart, logs)
|
|
106
|
+
β βββ cli.js # Terminal UI & formatting
|
|
107
|
+
βββ test/ # Automated test suite (node --test)
|
|
108
|
+
βββ docs/ # GitHub Pages portal & live terminal simulator
|
|
109
|
+
βββ package.json # Whitelisted files: ["bin", "src"], zero dependencies
|
|
110
|
+
βββ LICENSE # ISC License
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## π‘οΈ License
|
|
116
|
+
|
|
117
|
+
ISC License β [KeshavSoft](https://github.com/keshavsoft)
|
package/bin/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ubuntu-service",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"description": "Context-aware CLI to identify, inspect, restart, and view logs of the single systemd service running in the current directory on an Ubuntu VPS.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.js",
|
|
9
|
+
"./v1": "./src/v1/index.js",
|
|
10
|
+
"./v2": "./src/v2/index.js"
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"ubuntu-service": "bin/index.js",
|
|
14
|
+
"us": "bin/index.js"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"bin",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"start": "node bin/index.js",
|
|
22
|
+
"cli": "node bin/index.js",
|
|
23
|
+
"test": "node --test"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"ubuntu",
|
|
27
|
+
"systemd",
|
|
28
|
+
"service",
|
|
29
|
+
"vps",
|
|
30
|
+
"process",
|
|
31
|
+
"restart",
|
|
32
|
+
"cwd",
|
|
33
|
+
"caddy"
|
|
34
|
+
],
|
|
35
|
+
"author": "KeshavSoft",
|
|
36
|
+
"license": "ISC",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/keshavsoft/ubuntu-service.git"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/keshavsoft/ubuntu-service/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://keshavsoft.github.io/ubuntu-service/",
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18.0.0"
|
|
47
|
+
}
|
|
6
48
|
}
|
package/src/cli.js
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { findServiceForDirectory } from "./detector.js";
|
|
2
|
+
import { getServiceLiveStatus, restartService, getServiceLogs } from "./systemctl.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* High-level action to inspect the service for the current or target directory.
|
|
6
|
+
*/
|
|
7
|
+
export function inspectCurrentService(targetDir = process.cwd(), options = {}) {
|
|
8
|
+
const detected = findServiceForDirectory(targetDir, options);
|
|
9
|
+
if (!detected.found) {
|
|
10
|
+
return detected;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const liveStatus = getServiceLiveStatus(detected.unitName);
|
|
14
|
+
return {
|
|
15
|
+
...detected,
|
|
16
|
+
liveStatus
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* High-level action to restart the service associated with current or target directory.
|
|
22
|
+
*/
|
|
23
|
+
export function restartCurrentService(targetDir = process.cwd(), options = {}) {
|
|
24
|
+
const detected = findServiceForDirectory(targetDir, options);
|
|
25
|
+
if (!detected.found) {
|
|
26
|
+
return {
|
|
27
|
+
success: false,
|
|
28
|
+
error: detected.message,
|
|
29
|
+
targetDir
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const restartResult = restartService(detected.unitName);
|
|
34
|
+
return {
|
|
35
|
+
...detected,
|
|
36
|
+
restartResult
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* High-level action to get logs of the service associated with current or target directory.
|
|
42
|
+
*/
|
|
43
|
+
export function getCurrentServiceLogs(targetDir = process.cwd(), lines = 25, options = {}) {
|
|
44
|
+
const detected = findServiceForDirectory(targetDir, options);
|
|
45
|
+
if (!detected.found) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
error: detected.message,
|
|
49
|
+
targetDir
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const logsResult = getServiceLogs(detected.unitName, lines);
|
|
54
|
+
return {
|
|
55
|
+
...detected,
|
|
56
|
+
logsResult
|
|
57
|
+
};
|
|
58
|
+
}
|
package/src/v1/cli.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import {
|
|
2
|
+
inspectCurrentService,
|
|
3
|
+
restartCurrentService,
|
|
4
|
+
getCurrentServiceLogs
|
|
5
|
+
} from "./actions.js";
|
|
6
|
+
import { findServiceForDirectory } from "./detector.js";
|
|
7
|
+
|
|
8
|
+
export function printHelp() {
|
|
9
|
+
console.log(`
|
|
10
|
+
ubuntu-service (v1) β Single service management for the current directory
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
npx ubuntu-service [command] [options]
|
|
14
|
+
us [command] [options]
|
|
15
|
+
|
|
16
|
+
Commands:
|
|
17
|
+
(default) Inspect the systemd service running in the current directory
|
|
18
|
+
status Detailed status card for the current service
|
|
19
|
+
restart Restart only the service associated with the current directory
|
|
20
|
+
logs [-n <count>] View journalctl logs for the current service
|
|
21
|
+
name Output only the service unit name (e.g. appointment.keshavsoft.com.service)
|
|
22
|
+
port Output only the detected port (e.g. 3000)
|
|
23
|
+
|
|
24
|
+
Options:
|
|
25
|
+
--dir <path> Target a specific directory instead of process.cwd()
|
|
26
|
+
--systemd-dir <path> Custom systemd unit directory (defaults to /etc/systemd/system)
|
|
27
|
+
-n, --lines <count> Number of log lines to show (default: 25)
|
|
28
|
+
--json Output machine-readable JSON
|
|
29
|
+
-h, --help Show this help message
|
|
30
|
+
|
|
31
|
+
Aliases:
|
|
32
|
+
us Short alias for ubuntu-service
|
|
33
|
+
|
|
34
|
+
Examples:
|
|
35
|
+
# Stand in your project folder and run:
|
|
36
|
+
us
|
|
37
|
+
us restart
|
|
38
|
+
us logs -n 50
|
|
39
|
+
us name
|
|
40
|
+
`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function runCli(argv = process.argv.slice(2)) {
|
|
44
|
+
const isHelp = argv.includes("-h") || argv.includes("--help");
|
|
45
|
+
if (isHelp) {
|
|
46
|
+
printHelp();
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const isJson = argv.includes("--json");
|
|
51
|
+
|
|
52
|
+
// Parse options
|
|
53
|
+
let targetDir = process.cwd();
|
|
54
|
+
const dirIdx = argv.indexOf("--dir");
|
|
55
|
+
if (dirIdx !== -1 && argv[dirIdx + 1]) {
|
|
56
|
+
targetDir = argv[dirIdx + 1];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let systemdDir = null;
|
|
60
|
+
const sysIdx = argv.indexOf("--systemd-dir");
|
|
61
|
+
if (sysIdx !== -1 && argv[sysIdx + 1]) {
|
|
62
|
+
systemdDir = argv[sysIdx + 1];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let logLines = 25;
|
|
66
|
+
const nIdx = argv.findIndex(a => a === "-n" || a === "--lines");
|
|
67
|
+
if (nIdx !== -1 && argv[nIdx + 1]) {
|
|
68
|
+
const parsedN = parseInt(argv[nIdx + 1], 10);
|
|
69
|
+
if (!isNaN(parsedN) && parsedN > 0) {
|
|
70
|
+
logLines = parsedN;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const options = { systemdDir };
|
|
75
|
+
|
|
76
|
+
// Determine subcommand
|
|
77
|
+
const positionalArgs = argv.filter((arg, i) => {
|
|
78
|
+
if (arg.startsWith("-")) return false;
|
|
79
|
+
if (i > 0 && (argv[i - 1] === "--dir" || argv[i - 1] === "--systemd-dir" || argv[i - 1] === "-n" || argv[i - 1] === "--lines")) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const command = positionalArgs[0] || "status";
|
|
86
|
+
|
|
87
|
+
// Subcommand: name
|
|
88
|
+
if (command === "name") {
|
|
89
|
+
const detected = findServiceForDirectory(targetDir, options);
|
|
90
|
+
if (isJson) {
|
|
91
|
+
console.log(JSON.stringify(detected, null, 2));
|
|
92
|
+
} else if (detected.found) {
|
|
93
|
+
console.log(detected.unitName);
|
|
94
|
+
} else {
|
|
95
|
+
console.error(detected.message);
|
|
96
|
+
return 1;
|
|
97
|
+
}
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Subcommand: port
|
|
102
|
+
if (command === "port") {
|
|
103
|
+
const detected = findServiceForDirectory(targetDir, options);
|
|
104
|
+
if (isJson) {
|
|
105
|
+
console.log(JSON.stringify({ port: detected.port || null }, null, 2));
|
|
106
|
+
} else if (detected.found && detected.port) {
|
|
107
|
+
console.log(detected.port);
|
|
108
|
+
} else if (detected.found) {
|
|
109
|
+
console.log("No port configured or detected.");
|
|
110
|
+
} else {
|
|
111
|
+
console.error(detected.message);
|
|
112
|
+
return 1;
|
|
113
|
+
}
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Subcommand: restart
|
|
118
|
+
if (command === "restart") {
|
|
119
|
+
const res = restartCurrentService(targetDir, options);
|
|
120
|
+
if (isJson) {
|
|
121
|
+
console.log(JSON.stringify(res, null, 2));
|
|
122
|
+
return res.restartResult && res.restartResult.success ? 0 : 1;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!res.found) {
|
|
126
|
+
console.error(`\nβ No systemd service found for directory:\n ${res.targetDir}`);
|
|
127
|
+
console.error(`\nπ‘ Tip: Verify that /etc/systemd/system/*.service contains WorkingDirectory=${res.targetDir}\n Or run 'npx ubuntu-services' to see all services.`);
|
|
128
|
+
return 1;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
console.log(`\n===============================================================`);
|
|
132
|
+
console.log(` π ubuntu-service restart`);
|
|
133
|
+
console.log(`===============================================================`);
|
|
134
|
+
console.log(` π Directory: ${res.targetDir}`);
|
|
135
|
+
console.log(` π― Service Unit: ${res.unitName}`);
|
|
136
|
+
console.log(`---------------------------------------------------------------`);
|
|
137
|
+
|
|
138
|
+
if (res.restartResult && res.restartResult.success) {
|
|
139
|
+
const st = res.restartResult.status || {};
|
|
140
|
+
const stateText = st.isActive ? "π’ active (running)" : `π‘ ${st.activeState || "unknown"}`;
|
|
141
|
+
console.log(` β
Service successfully restarted!`);
|
|
142
|
+
console.log(` β‘ Status: ${stateText}`);
|
|
143
|
+
if (st.pid) console.log(` π Main PID: ${st.pid}`);
|
|
144
|
+
if (st.memory) console.log(` πΎ Memory: ${st.memory}`);
|
|
145
|
+
if (res.port) console.log(` π Port: ${res.port}`);
|
|
146
|
+
console.log(`===============================================================\n`);
|
|
147
|
+
return 0;
|
|
148
|
+
} else {
|
|
149
|
+
console.error(` β Restart failed!`);
|
|
150
|
+
if (res.restartResult && res.restartResult.error) {
|
|
151
|
+
console.error(` β οΈ Error: ${res.restartResult.error}`);
|
|
152
|
+
}
|
|
153
|
+
if (res.restartResult && res.restartResult.hint) {
|
|
154
|
+
console.error(` π‘ Hint: ${res.restartResult.hint}`);
|
|
155
|
+
}
|
|
156
|
+
console.log(`===============================================================\n`);
|
|
157
|
+
return 1;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Subcommand: logs
|
|
162
|
+
if (command === "logs" || command === "log") {
|
|
163
|
+
const res = getCurrentServiceLogs(targetDir, logLines, options);
|
|
164
|
+
if (isJson) {
|
|
165
|
+
console.log(JSON.stringify(res, null, 2));
|
|
166
|
+
return res.logsResult && res.logsResult.success ? 0 : 1;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!res.found) {
|
|
170
|
+
console.error(`\nβ No systemd service found for directory:\n ${res.targetDir}`);
|
|
171
|
+
return 1;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
console.log(`\nπ Logs for ${res.unitName} (last ${logLines} lines):`);
|
|
175
|
+
console.log(`---------------------------------------------------------------`);
|
|
176
|
+
if (res.logsResult && res.logsResult.success) {
|
|
177
|
+
console.log(res.logsResult.output || "(No recent logs)");
|
|
178
|
+
} else {
|
|
179
|
+
console.error(res.logsResult?.error || "Failed to retrieve logs");
|
|
180
|
+
}
|
|
181
|
+
console.log(`---------------------------------------------------------------\n`);
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Default / status command
|
|
186
|
+
const info = inspectCurrentService(targetDir, options);
|
|
187
|
+
|
|
188
|
+
if (isJson) {
|
|
189
|
+
console.log(JSON.stringify(info, null, 2));
|
|
190
|
+
return info.found ? 0 : 1;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!info.found) {
|
|
194
|
+
console.error(`\n===============================================================`);
|
|
195
|
+
console.error(` π ubuntu-service β No Service Match`);
|
|
196
|
+
console.error(`===============================================================`);
|
|
197
|
+
console.error(` π Current Directory: ${info.targetDir}`);
|
|
198
|
+
console.error(` β Status: No systemd service found for this folder.`);
|
|
199
|
+
console.error(`---------------------------------------------------------------`);
|
|
200
|
+
console.error(` π‘ Troubleshooting:`);
|
|
201
|
+
console.error(` 1. Ensure a service unit file in /etc/systemd/system/ has:`);
|
|
202
|
+
console.error(` WorkingDirectory=${info.targetDir}`);
|
|
203
|
+
console.error(` 2. Run 'npx ubuntu-services' to list all registered services.`);
|
|
204
|
+
console.error(` 3. If service uses a different path, test with:`);
|
|
205
|
+
console.error(` us --dir /path/to/folder`);
|
|
206
|
+
console.error(`===============================================================\n`);
|
|
207
|
+
return 1;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const live = info.liveStatus || {};
|
|
211
|
+
let statusBadge = "βͺ unknown";
|
|
212
|
+
if (live.available) {
|
|
213
|
+
if (live.isActive) {
|
|
214
|
+
statusBadge = `π’ active (${live.subState || "running"})`;
|
|
215
|
+
} else if (live.activeState === "failed") {
|
|
216
|
+
statusBadge = `π΄ failed (${live.subState})`;
|
|
217
|
+
} else {
|
|
218
|
+
statusBadge = `π‘ ${live.activeState || "inactive"} (${live.subState || "dead"})`;
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
statusBadge = "βͺ unqueried (systemctl unavailable)";
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
console.log(`\n===============================================================`);
|
|
225
|
+
console.log(` π― ubuntu-service β Single Service Card`);
|
|
226
|
+
console.log(`===============================================================`);
|
|
227
|
+
console.log(` π Directory: ${info.targetDir}`);
|
|
228
|
+
console.log(` π― Service Unit: ${info.unitName}`);
|
|
229
|
+
console.log(` β‘ State: ${statusBadge}`);
|
|
230
|
+
if (live.pid) console.log(` π Main PID: ${live.pid}`);
|
|
231
|
+
if (live.memory) console.log(` πΎ Memory: ${live.memory}`);
|
|
232
|
+
if (info.port) console.log(` π Port: ${info.port}`);
|
|
233
|
+
console.log(` π WorkingDir: ${info.workingDirectory || "-"} ${info.workingDirectoryExists ? "β
" : "β (missing)"}`);
|
|
234
|
+
console.log(` π ExecStart: ${info.execStart || "-"}`);
|
|
235
|
+
if (info.description) console.log(` π Description: ${info.description}`);
|
|
236
|
+
console.log(` π Match Reason: ${info.matchType} (confidence: ${info.score}%)`);
|
|
237
|
+
console.log(`---------------------------------------------------------------`);
|
|
238
|
+
console.log(` π‘ Quick Actions:`);
|
|
239
|
+
console.log(` us restart Restart this single service`);
|
|
240
|
+
console.log(` us logs View recent journalctl logs`);
|
|
241
|
+
console.log(` us name Output unit name`);
|
|
242
|
+
console.log(`===============================================================\n`);
|
|
243
|
+
|
|
244
|
+
return 0;
|
|
245
|
+
}
|