Skip to content

Commit 5a85449

Browse files
committed
Fix ReportCrash plist path in workflow, update Package.resolved dependencies, and enhance process management in pyeetd script
1 parent 79b1731 commit 5a85449

File tree

6 files changed

+158
-19
lines changed

6 files changed

+158
-19
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# macOS Runner Tuneup Action
2+
3+
Optimizes macOS GitHub runners by disabling resource-heavy background processes.
4+
5+
## Usage
6+
7+
```yaml
8+
- name: Optimize macOS Runner
9+
uses: ./.github/actions/macos-runner-tuneup
10+
```
11+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: 'macOS Runner Tuneup'
2+
description: 'Optimizes macOS GitHub runners by disabling resource-heavy background processes'
3+
author: 'Bitwarden'
4+
5+
runs:
6+
using: 'composite'
7+
steps:
8+
- name: Optimize macOS Runner
9+
shell: bash
10+
run: |
11+
echo "🚀 Starting macOS Runner Tuneup..."
12+
echo "=================================="
13+
14+
echo "🔍 Disabling Spotlight..."
15+
sudo mdutil -a -i off
16+
17+
echo "🛑 Disabling metadata services..."
18+
sudo launchctl disable system/com.apple.metadata.mds || true
19+
sudo launchctl disable system/com.apple.metadata.mds.index || true
20+
sudo launchctl disable system/com.apple.metadata.mds.scan || true
21+
22+
echo "📦 Unloading metadata plists..."
23+
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist || true
24+
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.index.plist || true
25+
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.scan.plist || true
26+
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mdwrite.plist || true
27+
28+
echo "⚡ Killing metadata processes..."
29+
sudo pkill -SIGKILL -f "Metadata.framework/Versions/A/Support/mds" || true
30+
sudo pkill -SIGKILL Spotlight || true
31+
echo "✅ Spotlight disabled!"
32+
33+
echo "💥 Disabling ReportCrash..."
34+
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.ReportCrash.plist || true
35+
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.ReportCrash.Root.plist || true
36+
sudo launchctl disable system/com.apple.ReportCrash || true
37+
sudo launchctl disable system/com.apple.ReportCrash.Root || true
38+
echo "✅ ReportCrash disabled!"
39+
40+
echo "🌱 Disabling EcosystemD..."
41+
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.ecosystemd.plist || true
42+
sudo pkill -SIGKILL -f "ecosystemd" || true
43+
echo "✅ EcosystemD disabled!"
44+
45+
echo "📊 Process Information After Tuning"
46+
echo "=================================="
47+
echo "🧠 Sorted by memory usage:"
48+
ps -em -o pid,pcpu,pmem,comm | head -n20
49+
echo ""
50+
echo "⚡ Sorted by CPU usage:"
51+
ps -er -o pid,pcpu,pmem,comm | head -n20
52+
echo ""
53+
echo "🎉 macOS Runner Tuneup Complete!"
54+

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ jobs:
146146
147147
echo "Disabling ReportCrash"
148148
echo "Unloading com.apple.ReportCrash.plist"
149-
sudo launchctl unload -w /System/Library/LaunchAgents/com.apple.ReportCrash.plist || true
149+
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.ReportCrash.plist || true
150150
echo "Unloading com.apple.ReportCrash.Root.plist"
151151
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.ReportCrash.Root.plist || true
152152
@@ -163,7 +163,6 @@ jobs:
163163
echo "com.apple.ecosystemd.plist disabled!"
164164
echo "--------------------------------"
165165
166-
167166
echo "Sorted by memory usage"
168167
ps -em -o pid,pcpu,pmem,comm | head -n40
169168
echo "--------------------------------"

Bitwarden.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Scripts/pyeetd/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# pyeetd
2+
3+
A minimal daemon implementation in Python, reimplemented from the Swift version at https://github.com/biscuitehh/yeetd.
4+
5+
## Usage
6+
7+
Make the script executable:
8+
```bash
9+
chmod +x main.py
10+
```
11+
12+
Run the daemon:
13+
```bash
14+
# Start the daemon
15+
./main.py start
16+
17+
# Check status
18+
./main.py status
19+
20+
# Stop the daemon
21+
./main.py stop
22+
23+
# Restart the daemon
24+
./main.py restart
25+
```
26+
27+
## Development
28+
29+
This project uses `uv` for Python version and package management:
30+
31+
```bash
32+
# Create virtual environment
33+
uv venv
34+
35+
# Activate environment
36+
source .venv/bin/activate # On Unix/macOS
37+
# or
38+
.venv\Scripts\activate # On Windows
39+
40+
# Install in development mode
41+
uv pip install -e .
42+
```
43+
44+
## Features
45+
46+
- Standard Unix daemon functionality
47+
- PID file management
48+
- Signal handling (SIGTERM, SIGINT)
49+
- Proper process forking and detachment
50+
- Logging support
51+
- No external dependencies (uses only Python standard library)

Scripts/pyeetd/main.py

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@
99
import subprocess
1010
import re
1111
from dataclasses import dataclass
12+
from enum import Enum
1213

13-
DEFAULT_PROCESSES = {
14+
OS_PROCESSES = {
15+
"Spotlight",
16+
"ReportCrash",
17+
"com.apple.ecosystemd",
18+
"com.apple.metadata.mds",
19+
"com.apple.metadata.mds.index",
20+
"com.apple.metadata.mds.scan",
21+
"com.apple.metadata.mdwrite",
22+
}
23+
24+
SIMULATOR_PROCESSES = {
1425
"AegirPoster",
1526
"InfographPoster",
1627
"CollectionsPoster",
@@ -27,18 +38,28 @@
2738
SIMULATOR_PATH_SEARCH_KEY = "simruntime/Contents/Resources/RuntimeRoot"
2839

2940
# How long to sleep between checks in seconds
30-
SLEEP_DELAY = 10
41+
SLEEP_DELAY = 5
3142

3243
@dataclass
3344
class ProcessInfo:
3445
pid: int
3546
cpu_percent: float
3647
memory_percent: float
3748
name: str
49+
is_simulator: bool
50+
51+
@property
52+
def environment(self) -> str:
53+
return "Simulator" if self.is_simulator else "OS"
3854

39-
def get_processes():
55+
class ProcessSort(Enum):
56+
CPU = "cpu"
57+
MEMORY = "memory"
58+
59+
def get_processes(sort_by=ProcessSort.CPU):
4060
"""Get all processes using ps command - equivalent to Swift's proc_listallpids"""
41-
result = subprocess.run(['ps', '-ero', 'pid,pcpu,pmem,comm'],
61+
sorty_by = "-ero" if sort_by == ProcessSort.CPU else "-emo"
62+
result = subprocess.run(['ps', sorty_by, 'pid,pcpu,pmem,comm'],
4263
capture_output=True, text=True, check=True)
4364
processes = []
4465

@@ -49,39 +70,42 @@ def get_processes():
4970
cpu_percent = float(parts[1])
5071
memory_percent = float(parts[2])
5172
name = parts[3]
52-
processes.append(ProcessInfo(pid, cpu_percent, memory_percent, name))
73+
is_simulator = SIMULATOR_PATH_SEARCH_KEY in name
74+
processes.append(ProcessInfo(pid, cpu_percent, memory_percent, name, is_simulator))
5375

5476
return processes
5577

56-
def print_processes(processes):
78+
def print_processes(processes, max_processes=-1):
5779
print("PID\tCPU%\tMemory%\tName")
58-
for p in processes:
59-
print(f"{p.pid}\t{p.cpu_percent}%\t{p.memory_percent}%\t{p.name}")
80+
max_processes = len(processes) if max_processes == -1 else max_processes
81+
for p in processes[:max_processes]:
82+
print(f"{p.pid}\t{p.cpu_percent}%\t{p.memory_percent}%\t{p.name}\t{p.environment}")
6083

6184
def find_unwanted(processes):
6285
yeeting = []
6386
for p in processes:
64-
for k in DEFAULT_PROCESSES:
87+
process_target_list = SIMULATOR_PROCESSES if p.is_simulator else OS_PROCESSES
88+
for k in process_target_list:
6589
if k in p.name:
6690
yeeting.append(p)
6791
return yeeting
6892

6993
def yeet(processes):
7094
output = []
7195
for p in processes:
72-
output.append(f"pyeetd: Stopping - {p.pid} {p.cpu_percent}% {p.memory_percent}% {p.name}")
96+
output.append(f"pyeetd: Stopping - {p.pid} {p.cpu_percent}% {p.memory_percent}% {p.name} {p.environment}")
7397
os.killpg(p.pid, signal.SIGKILL)
7498
return output
7599

76100
def main():
101+
# processes = get_processes(ProcessSort.CPU)
102+
# print_processes(processes, 20)
77103
while True:
78104
output = []
79-
output.append(f"{time.strftime('%Y-%m-%d %H:%M:%S')} - pyeetd scanning...")
80-
processes = get_processes()
81-
#print_processes(processes)
105+
processes = get_processes(ProcessSort.CPU)
82106
processes_to_yeet = find_unwanted(processes)
83107
output.extend(yeet(processes_to_yeet))
84-
output.append(f"{time.strftime('%Y-%m-%d %H:%M:%S')} - pyeetd {len(processes_to_yeet)} processes!")
108+
output.append(f"{time.strftime('%Y-%m-%d %H:%M:%S')} - pyeetd {len(processes_to_yeet)} processes.")
85109
print("\n".join(output))
86110
time.sleep(SLEEP_DELAY)
87111

0 commit comments

Comments
 (0)