-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
106 lines (90 loc) · 2.69 KB
/
Copy pathjustfile
File metadata and controls
106 lines (90 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# launchd service label (override: just LABEL=com.you.localhome install)
service := env_var_or_default("LABEL", "com.localhome")
plist := "~/Library/LaunchAgents/" + service + ".plist"
# NAME the daemon registers itself under (its dashboard route)
name := env_var_or_default("NAME", "home")
repo := justfile_directory()
rendered := repo / "launchd" / service + ".local.plist"
# Show all commands
[private]
default:
@just --list
# Run the daemon
[group('dev')]
run:
NAME={{name}} bun run src/index.ts
# Run with watch mode
[group('dev')]
dev:
NAME={{name}} bun run --watch src/index.ts
# Run tests
[group('test')]
test:
bun test
# Scan for running servers (debug)
[group('debug')]
scan:
bun run src/scan.ts
# Run a test server (use LOCALHOST_NAME=foo just test-server)
[group('debug')]
test-server:
bun run src/test-server.ts
# Build binary
[group('build')]
build:
bun build src/index.ts --compile --outfile bin/localhome
# Render the launchd plist from the template for this machine (gitignored output)
[group('service')]
render:
#!/usr/bin/env bash
set -euo pipefail
bun_path="$(command -v bun)"
path_dir="$(dirname "$bun_path")"
sed \
-e "s#@LABEL@#{{service}}#g" \
-e "s#@BUN@#${bun_path}#g" \
-e "s#@REPO@#{{repo}}#g" \
-e "s#@HOME@#${HOME}#g" \
-e "s#@NAME@#{{name}}#g" \
-e "s#@PATH@#${path_dir}:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin#g" \
"{{repo}}/launchd/com.localhome.plist.template" > "{{rendered}}"
echo "Rendered {{rendered}}"
# Start the service
[group('service')]
start:
launchctl bootstrap gui/$(id -u) {{plist}}
# Stop the service
[group('service')]
stop:
launchctl bootout gui/$(id -u)/{{service}}
# Restart the service
[group('service')]
restart:
launchctl kickstart -k gui/$(id -u)/{{service}}
# Show service status
[group('service')]
status:
@launchctl list | grep {{service}} || echo "Service not loaded"
@echo "---"
@lsof -i :9090 2>/dev/null || echo "Port 9090 not listening"
# View logs
[group('service')]
logs:
tail -f ~/Library/Logs/localhome.log
# View error logs
[group('service')]
errors:
tail -f ~/Library/Logs/localhome.error.log
# Render + install/reinstall the plist (generates from template, then loads it)
[group('service')]
install: render
cp {{rendered}} {{plist}}
launchctl bootout gui/$(id -u)/{{service}} 2>/dev/null || true
launchctl bootstrap gui/$(id -u) {{plist}}
@echo "Installed and started. Check: just status"
# Uninstall the service completely
[group('service')]
uninstall:
launchctl bootout gui/$(id -u)/{{service}} 2>/dev/null || true
rm -f {{plist}}
@echo "Service uninstalled. Logs remain at ~/Library/Logs/localhome*.log"