🎉 Project init
This commit is contained in:
parent
25aed8ce0f
commit
67108e5529
4 changed files with 112 additions and 2 deletions
45
README.md
45
README.md
|
@ -1,3 +1,44 @@
|
|||
# jellyfin-wol
|
||||
# Jellyfin WOL
|
||||
|
||||
Wake up your NAS or another server on your LAN when someone logs into your Jellyfin.
|
||||
Wake up your NAS or another server on your LAN when someone logs into your Jellyfin.
|
||||
|
||||
## Installation
|
||||
|
||||
Clone or copy the files and place them here:
|
||||
|
||||
|
||||
```
|
||||
/usr/local/bin/jellyfin_wol.py
|
||||
/etc/systemd/system/jellyfin-wol.service
|
||||
```
|
||||
|
||||
Create a `.env` at `/etc/jellyfin_wol_environment` with following content:
|
||||
|
||||
```
|
||||
MAC_ADDRESS=1c:1b:0d:99:5c:48
|
||||
LISTEN_ADDRESS=0.0.0.0
|
||||
LISTEN_PORT=8092
|
||||
```
|
||||
|
||||
Set the MAC address to the one you want to wake up.
|
||||
|
||||
Enable and start the service:
|
||||
|
||||
```
|
||||
systemctl enable jellyfin-wol
|
||||
systemctl start jellyfin-wol
|
||||
```
|
||||
|
||||
Install the Jellyfin webhook plugin and click **Add Generic Form Destination**. Give ti some name, set the URL to
|
||||
`http://your-jellyfin:8092`, change the hostname and port as neeed. Make sure **Status** is enabled and
|
||||
**Notification Type** has "Authentication Success" checked.
|
||||
|
||||
Scroll down to **Item Types** and make sure these two options are checked:
|
||||
|
||||
- Send All Properties (ignores template)
|
||||
- Trim leading and trailing whitespace from message body before sending
|
||||
|
||||
Hit **Save**, log out and log in again. The magic packet now has been sent.
|
||||
|
||||
Check the `mount_nas` script, maybe it could be helpful. I run it as a cron every minute to mount the NFS share after the
|
||||
NAS becomes online. As a last step I restart the Jellyfin container (the NAS share is mounted via docker volume).
|
||||
|
|
13
jellyfin-wol.service
Normal file
13
jellyfin-wol.service
Normal file
|
@ -0,0 +1,13 @@
|
|||
[Unit]
|
||||
Description=Jellyfin WOL Service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
#EnvironmentFile=/etc/powermeter-environment
|
||||
ExecStart=/usr/local/bin/jellyfin_wol.py
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
31
jellyfin_wol.py
Executable file
31
jellyfin_wol.py
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/python3
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
from urllib.parse import parse_qs
|
||||
from wakeonlan import send_magic_packet
|
||||
import os
|
||||
|
||||
|
||||
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
raw_data = self.rfile.read(content_length).decode('utf-8')
|
||||
post_data = parse_qs(raw_data)
|
||||
|
||||
# Check if the payload indicates a user login event
|
||||
if 'NotificationType' in post_data and 'AuthenticationSuccess' in post_data['NotificationType']:
|
||||
print("User login detected! Waking up NAS.")
|
||||
send_magic_packet('1c:1b:0d:99:5c:48')
|
||||
|
||||
# Send a 200 OK response
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(b'{"status": "success"}')
|
||||
|
||||
|
||||
# Configure and start the HTTP server
|
||||
if __name__ == '__main__':
|
||||
host = os.getenv('LISTEN_ADDRESS', '0.0.0.0')
|
||||
port = int(os.getenv('LISTEN_PORT', 8092))
|
||||
httpd = HTTPServer((host, port), SimpleHTTPRequestHandler)
|
||||
print(f"Listening on {host}:{port}...")
|
||||
httpd.serve_forever()
|
25
mount_nas.sh
Executable file
25
mount_nas.sh
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Automatically mount NFS share if NAs becomes available.
|
||||
# Restart jellyfin container after mounting.
|
||||
|
||||
DIR="/mnt/Medien"
|
||||
|
||||
ping 192.168.1.3 -c 1 > /dev/null 2>&1
|
||||
PING_STATUS=$?
|
||||
mount | grep "$DIR" > /dev/null 2>&1
|
||||
NAS_MOUNT=$?
|
||||
|
||||
if [ "$PING_STATUS" -eq 0 ]; then
|
||||
# Host reachable
|
||||
if [ "$NAS_MOUNT" -eq 1 ]; then
|
||||
# nout mounted yet
|
||||
mount "$DIR" && cd /opt/stacks/jellyfin/ && docker compose down && docker compose up -d
|
||||
fi
|
||||
else
|
||||
if [ $NAS_MOUNT -eq 0 ]; then
|
||||
# still mounted
|
||||
umount -l "$DIR"
|
||||
fi
|
||||
fi
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue