Configured logging & added systemd unit
This commit is contained in:
parent
63543d6c1e
commit
2cc80506b5
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ epd_4in2_test.py
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
lib/
|
lib/
|
||||||
img/Font.ttc
|
img/Font.ttc
|
||||||
|
*.log
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
\- **\_\_pycache\_\_/** - aint nobody got time for compiled python binaries.
|
\- **\_\_pycache\_\_/** - aint nobody got time for compiled python binaries.
|
||||||
\- **lib/** - library files from waveshare, available on their github page.
|
\- **lib/** - library files from waveshare, available on their github page.
|
||||||
\- **img/Font.ttc** - font file provided by waveshare, available on their github page.
|
\- **img/Font.ttc** - font file provided by waveshare, available on their github page.
|
||||||
|
\- **\*.log** - nobody needs the log files in their repo
|
||||||
|
|
||||||
**ePaper Pins:**
|
**ePaper Pins:**
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ libdir = "/home/pi/epaper/lib"#os.path.join(os.path.dirname(os.path.dirname(os.p
|
|||||||
if os.path.exists(libdir):
|
if os.path.exists(libdir):
|
||||||
sys.path.append(libdir)
|
sys.path.append(libdir)
|
||||||
|
|
||||||
import logging
|
import logging,logging.handlers
|
||||||
from waveshare_epd import epd4in2
|
from waveshare_epd import epd4in2
|
||||||
import time
|
import time
|
||||||
from PIL import Image,ImageDraw,ImageFont
|
from PIL import Image,ImageDraw,ImageFont
|
||||||
@ -36,6 +36,11 @@ requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
|||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
#logging.basicConfig(level=logging.INFO)
|
#logging.basicConfig(level=logging.INFO)
|
||||||
|
logger=logging.getLogger('octopimonitor')
|
||||||
|
formatter=logging.Formatter('[{asctime}] [{levelname:<8}] {name}: {message}', '%Y-%m-%d %H:%M:%S', style='{')
|
||||||
|
handler=logging.handlers.RotatingFileHandler(filename='octopimonitor.log', encoding='utf-8', maxBytes=32*1024*1024, backupCount=5)
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(handler)
|
||||||
|
|
||||||
def timestr(time):
|
def timestr(time):
|
||||||
return f"{datestr(time)} {time.hour:02}:{time.minute:02}"
|
return f"{datestr(time)} {time.hour:02}:{time.minute:02}"
|
||||||
|
24
octomonitor.service
Normal file
24
octomonitor.service
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Adjust the paths below as necessary
|
||||||
|
# (WorkingDirectory & ExecStart)
|
||||||
|
# Copy this file to /etc/systemd/system/
|
||||||
|
# Run 'sudo systemctl daemon-reload'
|
||||||
|
# Now you can 'sudo systemctl [start|stop|reload] octomonitor'
|
||||||
|
# Run 'sudo systemctl enable octomonitor' if
|
||||||
|
# you want the service to start on boot
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=Octopi ePaper Monitor
|
||||||
|
After=syslog.target
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
RestartSec=30s
|
||||||
|
Type=simple
|
||||||
|
User=pi
|
||||||
|
Group=pi
|
||||||
|
WorkingDirectory=/home/pi/epaper/
|
||||||
|
ExecStart=/usr/bin/python3 /home/pi/epaper/octomonitor.py
|
||||||
|
Restart=on-failure
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
x
Reference in New Issue
Block a user