Commit 5eb42b64 authored by Soldatoff's avatar Soldatoff

Изменил название сервиса и добавил перезапуск

parent 04e96fe7
%define biname nginx-redirector
Name: nginx-redirector
Version: 0.1.7
Version: 0.1.8
Release: alt1
Summary: CLI-utility for building nginx redirects
......@@ -26,10 +26,10 @@ BuildArch: noarch
%description
NGINX redirector:
* redirector <.yaml file> <.map file> - generate .conf and .map files for redirects for nginx
* redirector-watch <file-to-watch> - set inotify watchdog for this file and renew .map and .conf files for this project when
* redirector-convert <.htaccess file> <.map file> - convert .htaccess to .map file
* redirector-config --show - show all current config.ini data
* nginx-redirector <.yaml file> <.map file> - generate .conf and .map files for redirects for nginx
* nginx-redirector-watch <file-to-watch> - set inotify watchdog for this file and renew .map and .conf files for this project when
* nginx-redirector-convert <.htaccess file> <.map file> - convert .htaccess to .map file
* nginx-redirector-config --show - show all current config.ini data
%prep
%setup
......@@ -42,9 +42,10 @@ NGINX redirector:
mkdir -p %buildroot/var/lib/%biname/location-includes
mkdir -p %buildroot/var/lib/%biname/maps
mkdir -p %buildroot/etc/%biname
mkdir -p %buildroot/var/log/%biname
#cp nginx-redirector-watch.service %buildroot/etc/systemd/system/nginx-redirector-watch.service
install -pD -m644 nginx-redirector-watch.service %buildroot%systemd_unitdir/nginx-redirector-watch.service
install -pD -m644 nginx-redirector.service %buildroot%systemd_unitdir/nginx-redirector.service
%files
/usr/bin/%biname
......@@ -53,6 +54,7 @@ install -pD -m644 nginx-redirector-watch.service %buildroot%systemd_unitdir/ngin
/var/lib/%biname/location-includes/
/var/lib/%biname/maps/
/var/log/%biname
/etc/%biname/
%systemd_unitdir/*
......
......@@ -5,11 +5,11 @@ Installation:
Usage:
`$ redirector <.yaml file> <.map file>` - generate .conf and .map files for redirects for nginx
`$ nginx-redirector <.yaml file> <.map file>` - generate .conf and .map files for redirects for nginx
`$ redirector-watch <file-to-watch>` - set inotify watchdog for this file and renew .map and .conf files for this project when file content is changed
`$ nginx-redirector-watch <file-to-watch>` - set inotify watchdog for this file and renew .map and .conf files for this project when file content is changed
`$ redirector-convert <.htaccess file> <.map file>` - convert .htaccess to .map file
`$ nginx-redirector-convert <.htaccess file> <.map file>` - convert .htaccess to .map file
......
[Unit]
Description=service for redirector
Description=service for nginx-redirector
[Service]
Type=simple
......
import os
import pyinotify
import subprocess
import argparse as ap
from redirector.utils import generators
......@@ -14,13 +15,12 @@ redirector_watch = None
class RedirectorWatch:
def __init__(self):
self.logger = logger.Logger("redirector-watch.log")
self.logger = logger.Logger("/var/log/nginx-redirector/redirector-watch.log")
self.redirector = Redirector()
self.parser = parser.ConfigReader(logger=self.logger)
self.mask = pyinotify.ALL_EVENTS
self.pool = {}
def watch(self, yaml_file):
if not yaml_file:
raise self.RedirectorWatchException("yaml_file list is empty", Exception)
......@@ -42,6 +42,17 @@ class RedirectorWatch:
# creating class Watch with custom static 'yaml_file' argument
def create_watch_class(self, yaml_file):
global redirector_watch
def reload_service(service):
#reload systemd service.
try:
cmd = '/bin/systemctl reload {}.service'.format(service)
completed = subprocess.run( cmd, shell=True, check=True, stdout=subprocess.PIPE )
print("completed reload_service")
print( str ( completed ))
except subprocess.CalledProcessError as err:
print( 'ERROR:', err )
class Watch(pyinotify.ProcessEvent):
def __init__(self, *args, **kwargs):
self.redirector = kwargs.pop("redirector")
......@@ -55,6 +66,7 @@ class RedirectorWatch:
redirector_watch.pool[yaml_file] = None
print("Proccessing...")
self.redirector.generate(yaml_file, event.pathname)
reload_service("nginx")
redirector_watch.watch(yaml_file)
# fix bug with vim editing
......@@ -65,6 +77,7 @@ class RedirectorWatch:
corr_path = event.pathname.replace('-unknown-path', '')
print("Processing...")
self.redirector.generate(yaml_file, corr_path)
reload_nginx("nginx")
redirector_watch.watch(yaml_file)
return Watch
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment