From 1b977577d5474faa1ec8857f33346c5d36584211 Mon Sep 17 00:00:00 2001 From: Wojciech Kosior Date: Wed, 17 Jun 2020 14:44:09 +0200 Subject: make logfile writeble by 0tdns user --- src/hourly.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/hourly.py b/src/hourly.py index ecf1f10..c8fc308 100755 --- a/src/hourly.py +++ b/src/hourly.py @@ -2,15 +2,17 @@ from sys import argv import subprocess -from os import path, waitpid, unlink, WEXITSTATUS +from os import path, waitpid, unlink, WEXITSTATUS, chown from time import gmtime, strftime, sleep import re +from pathlib import Path +from pwd import getpwnam import psycopg2 # our own module used by several scripts in the project from ztdnslib import start_db_connection, \ - get_default_host_address, get_ztdns_config, log, set_loghour + get_default_host_address, get_ztdns_config, log, set_loghour, logfile wrapper = '/var/lib/0tdns/vpn_wrapper.sh' perform_queries = '/var/lib/0tdns/perform_queries.py' @@ -248,10 +250,18 @@ def do_hourly_work(hour): connection.close() +def prepare_logging(hour): + set_loghour(hour) # log() function will now prepend messages with hour + + Path(logfile).touch() # ensure logfile exists + + # enable 0tdns user to write to logfile + chown(logfile, getpwnam('0tdns').pw_uid, -1) + # round down to an hour - this datetime format is one # of the formats accepted by postgres hour = strftime('%Y-%m-%d %H:00%z', gmtime()) -set_loghour(hour) # log() function will now prepend messages with hour +prepare_logging(hour) if not lock_on_file(): log('Failed trying to run for {}; {} exists'.format(hour, lockfile)) -- cgit v1.2.3