zinkwazi / wspr-zero

WSPR-zero turns a Raspberry Pi Zero into a WSPR transmitter and receiver perfect for traveling.
2 stars 0 forks source link

Log file permissions error #2

Closed zinkwazi closed 1 month ago

zinkwazi commented 1 month ago

setup-post.log and wspr-zero-shutdown.log are being written as root which is causing issues including the setup mode script.

pi@wspr-dev:~ $ python wspr-zero/scripts/server_checkin.py Traceback (most recent call last): File "/home/pi/wspr-zero/scripts/server_checkin.py", line 110, in main() File "/home/pi/wspr-zero/scripts/server_checkin.py", line 78, in main stop_wspr() File "/home/pi/wspr-zero/scripts/server_checkin.py", line 67, in stop_wspr log_message("Stopping WSPR process") File "/home/pi/wspr-zero/scripts/server_checkin.py", line 43, in log_message with open(log_file, 'a') as file: PermissionError: [Errno 13] Permission denied: '/home/pi/wspr-zero/logs/setup-post.log'

pi@wspr-dev:~/wspr-zero $ ls -alh logs/ total 76K drwxr-xr-x 2 pi pi 4.0K Jun 5 09:05 . drwxr-xr-x 7 pi pi 4.0K Jun 4 21:36 .. -rw-r--r-- 1 pi pi 82 Apr 25 21:17 .gitignore -rw-r--r-- 1 root root 2.0K Jun 4 23:30 setup-post.log -rw-r--r-- 1 pi pi 52K Jun 5 18:14 wspr-transmit.log -rw-r--r-- 1 root root 558 Jun 5 18:02 wspr-zero-shutdown.log

zinkwazi commented 1 month ago

Fixed permissions in utility-button.py when the pi boots and makes the log files and folder.

Get the UID of the user running the script

user = pwd.getpwnam("pi") uid = user.pw_uid gid = user.pw_gid

Set up logging

log_file = '/home/pi/wspr-zero/logs/wspr-zero-shutdown.log' if not os.path.exists(log_file): open(log_file, 'a').close() # Create the log file if it doesn't exist os.chown(log_file, uid, gid) # Change ownership of the log file os.chmod(log_file, 0o664) # Set appropriate permissions for the log file