-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynd.py
More file actions
executable file
·45 lines (34 loc) · 1023 Bytes
/
synd.py
File metadata and controls
executable file
·45 lines (34 loc) · 1023 Bytes
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
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
"""Tiny Synology DiskStation daemon
The service will turn off the blinking LED at startup and shut the
system down when the power button is pressed.
"""
import os
import signal
import sys
from serial import Serial
UART_PORT = "/dev/ttyS1"
POWER_BUTTON_PRESSED = b'0'
CMD_LED_POWER_BLINK = b'5'
CMD_LED_POWER_OFF = b'6'
CMD_RCPOWERON = b'q'
def sigterm_handler(_signo, _stack_frame):
sys.exit(0)
def wait_for_button_press(uart):
while True:
in_byte = uart.read(1)
if in_byte == POWER_BUTTON_PRESSED:
print("Triggering system shutdown...")
os.system('/usr/sbin/poweroff')
if __name__ == '__main__':
signal.signal(signal.SIGTERM, sigterm_handler)
uart = Serial(UART_PORT, 9600, timeout=1)
try:
uart.write(CMD_LED_POWER_OFF)
uart.write(CMD_RCPOWERON)
wait_for_button_press(uart)
finally:
if uart:
uart.write(CMD_LED_POWER_BLINK)
uart.close()