Commit 5eb42b64 authored by Soldatoff's avatar Soldatoff

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

parent 04e96fe7
%define biname nginx-redirector %define biname nginx-redirector
Name: nginx-redirector Name: nginx-redirector
Version: 0.1.7 Version: 0.1.8
Release: alt1 Release: alt1
Summary: CLI-utility for building nginx redirects Summary: CLI-utility for building nginx redirects
...@@ -26,10 +26,10 @@ BuildArch: noarch ...@@ -26,10 +26,10 @@ BuildArch: noarch
%description %description
NGINX redirector: NGINX redirector:
* 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 * 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 * nginx-redirector-convert <.htaccess file> <.map file> - convert .htaccess to .map file
* redirector-config --show - show all current config.ini data * nginx-redirector-config --show - show all current config.ini data
%prep %prep
%setup %setup
...@@ -42,9 +42,10 @@ NGINX redirector: ...@@ -42,9 +42,10 @@ NGINX redirector:
mkdir -p %buildroot/var/lib/%biname/location-includes mkdir -p %buildroot/var/lib/%biname/location-includes
mkdir -p %buildroot/var/lib/%biname/maps mkdir -p %buildroot/var/lib/%biname/maps
mkdir -p %buildroot/etc/%biname mkdir -p %buildroot/etc/%biname
mkdir -p %buildroot/var/log/%biname
#cp nginx-redirector-watch.service %buildroot/etc/systemd/system/nginx-redirector-watch.service #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 %files
/usr/bin/%biname /usr/bin/%biname
...@@ -53,6 +54,7 @@ install -pD -m644 nginx-redirector-watch.service %buildroot%systemd_unitdir/ngin ...@@ -53,6 +54,7 @@ install -pD -m644 nginx-redirector-watch.service %buildroot%systemd_unitdir/ngin
/var/lib/%biname/location-includes/ /var/lib/%biname/location-includes/
/var/lib/%biname/maps/ /var/lib/%biname/maps/
/var/log/%biname
/etc/%biname/ /etc/%biname/
%systemd_unitdir/* %systemd_unitdir/*
......
...@@ -5,11 +5,11 @@ Installation: ...@@ -5,11 +5,11 @@ Installation:
Usage: 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] [Unit]
Description=service for redirector Description=service for nginx-redirector
[Service] [Service]
Type=simple Type=simple
......
import os import os
import pyinotify import pyinotify
import subprocess
import argparse as ap import argparse as ap
from redirector.utils import generators from redirector.utils import generators
...@@ -14,13 +15,12 @@ redirector_watch = None ...@@ -14,13 +15,12 @@ redirector_watch = None
class RedirectorWatch: class RedirectorWatch:
def __init__(self): 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.redirector = Redirector()
self.parser = parser.ConfigReader(logger=self.logger) self.parser = parser.ConfigReader(logger=self.logger)
self.mask = pyinotify.ALL_EVENTS self.mask = pyinotify.ALL_EVENTS
self.pool = {} self.pool = {}
def watch(self, yaml_file): def watch(self, yaml_file):
if not yaml_file: if not yaml_file:
raise self.RedirectorWatchException("yaml_file list is empty", Exception) raise self.RedirectorWatchException("yaml_file list is empty", Exception)
...@@ -42,6 +42,17 @@ class RedirectorWatch: ...@@ -42,6 +42,17 @@ class RedirectorWatch:
# creating class Watch with custom static 'yaml_file' argument # creating class Watch with custom static 'yaml_file' argument
def create_watch_class(self, yaml_file): def create_watch_class(self, yaml_file):
global redirector_watch 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): class Watch(pyinotify.ProcessEvent):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.redirector = kwargs.pop("redirector") self.redirector = kwargs.pop("redirector")
...@@ -55,6 +66,7 @@ class RedirectorWatch: ...@@ -55,6 +66,7 @@ class RedirectorWatch:
redirector_watch.pool[yaml_file] = None redirector_watch.pool[yaml_file] = None
print("Proccessing...") print("Proccessing...")
self.redirector.generate(yaml_file, event.pathname) self.redirector.generate(yaml_file, event.pathname)
reload_service("nginx")
redirector_watch.watch(yaml_file) redirector_watch.watch(yaml_file)
# fix bug with vim editing # fix bug with vim editing
...@@ -65,6 +77,7 @@ class RedirectorWatch: ...@@ -65,6 +77,7 @@ class RedirectorWatch:
corr_path = event.pathname.replace('-unknown-path', '') corr_path = event.pathname.replace('-unknown-path', '')
print("Processing...") print("Processing...")
self.redirector.generate(yaml_file, corr_path) self.redirector.generate(yaml_file, corr_path)
reload_nginx("nginx")
redirector_watch.watch(yaml_file) redirector_watch.watch(yaml_file)
return Watch 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