-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patholed-openrc
More file actions
65 lines (53 loc) · 1.5 KB
/
Copy patholed-openrc
File metadata and controls
65 lines (53 loc) · 1.5 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
#!/sbin/openrc-run
description="OLED Control Service"
pidfile="/run/oled.pid"
logfile="/var/log/oled.log"
workdir="/opt/oledctrl/oled"
venv="/opt/oledctrl/venv/bin/python3"
program="/opt/oledctrl/oled/oled.py"
start() {
ebegin "Starting ${description}"
if [ -f "${pidfile}" ]; then
local pid=$(cat "${pidfile}")
if kill -0 "$pid" 2>/dev/null; then
eend 1 "Service already running (PID: $pid)"
return 1
fi
fi
cd "${workdir}"
PYTHONUNBUFFERED=1 ${venv} ${program} >> "${logfile}" 2>&1 &
echo $! > "${pidfile}"
eend $?
}
stop() {
ebegin "Stopping ${description}"
if [ -f "${pidfile}" ]; then
local pid=$(cat "${pidfile}")
if kill -0 "$pid" 2>/dev/null; then
kill -TERM "$pid"
# Wait for process exit using SIGTERM
local count=0
while kill -0 "$pid" 2>/dev/null && [ $count -lt 15 ]; do
sleep 1
count=$((count + 1))
done
# If process is frozen, force terminate it
if kill -0 "$pid" 2>/dev/null; then
kill -9 "$pid"
fi
fi
rm -f "${pidfile}"
fi
eend $?
}
status() {
if [ -f "${pidfile}" ]; then
local pid=$(cat "${pidfile}")
if kill -0 "$pid" 2>/dev/null; then
einfo "Service is running (PID: $pid)"
return 0
fi
fi
einfo "Service is stopped"
return 1
}