Fix logs management

parent a31f7ac5
......@@ -42,23 +42,37 @@ Rendez-vous dans le dossier HOME de votre utilisateur duniter (par ex : /var/lib
cd /var/lib/duniter/ && sudo -u duniter git clone https://git.duniter.org/paidge/wotmap.git
### III. Automatisation de la mise à jour des données (CRON)
Créez le fichier ***/etc/cron.d/wotmap*** sur votre serveur pour automatiser le lancement du script :
* Créez le dossier qui accueillera les logs (l'utilisateur duniter doit avoir les droits d'écriture) :
sudo mkdir /var/log/wotmap && chown -R duniter:duniter /var/log/wotmap
* Créez le fichier ***/etc/cron.d/wotmap*** sur votre serveur pour automatiser le lancement du script :
30 3 * * 0-5 duniter python3 /var/lib/duniter/wotmap/script/wot_json.py >> /var/log/wotmap/wotmap.log 2>&1
30 3 * * 6 duniter python3 /var/lib/duniter/wotmap/script/wot_json.py -d >> /var/log/wotmap/wotmap.log 2>&1
30 3 * * 6 duniter python3 /var/lib/duniter/wotmap/script/wot_json.py -d 2>&1 | /var/lib/duniter/wotmap/logs/timestamp.sh >> /var/lib/duniter/wotmap/wotmap.log
30 3 * * 0-5 duniter python3 /var/lib/duniter/wotmap/script/wot_json.py 2>&1 | /var/lib/duniter/wotmap/logs/timestamp.sh >> /var/lib/duniter/wotmap/wotmap.log
### IV. Paramétrage d'Apache
<VirtualHost *:443>
ServerName mondomaine.fr
DocumentRoot /var/lib/duniter/wotmap/
<Directory /var/lib/duniter/wotmap/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
Header set Access-Control-Allow-Origin '*'
</Directory>
SSLCertificateFile /etc/letsencrypt/live/mondomaine.fr/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mondomaine.fr/privkey.pem
</VirtualHost>
\ No newline at end of file
* Créez un virtualhost pour votre nom de domaine
sudo nano /etc/apache2/sites-available/mondomaine.fr.conf
* Pour y placer votre configuration :
<VirtualHost *:443>
ServerName mondomaine.fr
DocumentRoot /var/lib/duniter/wotmap/
<Directory /var/lib/duniter/wotmap/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
Header set Access-Control-Allow-Origin '*'
</Directory>
SSLCertificateFile /etc/letsencrypt/live/mondomaine.fr/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mondomaine.fr/privkey.pem
</VirtualHost>
* Puis activez-le :
sudo a2ensite mondomaine.fr.conf
sudo systemctl reload apache2
\ No newline at end of file
#!/bin/bash
while read x; do
echo -n `date +%d/%m/%Y\ %H:%M:%S`;
echo -n " ";
echo $x;
done
\ No newline at end of file
......@@ -8,11 +8,10 @@ Command for installing:
$ sudo pip3 install plyvel python-igraph
"""
import sys, os, time, math, json, urllib.request, colorsys, plyvel, igraph
import sys, os, time, math, json, urllib.request, colorsys, plyvel, igraph, subprocess
VERSION = "0.1.0"
STEPMAX = 5
verbose = False
def getargv(arg, default=""):
if arg in sys.argv and len(sys.argv) > sys.argv.index(arg)+1:
......@@ -20,9 +19,19 @@ def getargv(arg, default=""):
else:
return default
def log(msg, end="\n"):
if verbose:
print(msg, end=end)
LOG_TRACE = 1
LOG_INFO = 2
LOG_WARN = 4
LOG_ERROR = 8
LOGMSG_TYPES = {LOG_INFO:"\033[96minfo\033[0m", LOG_TRACE:"\033[39mtrace\033[0m", LOG_WARN:"\033[93mwarn\033[0m", LOG_ERROR:"\033[91merror\033[0m"}
VERBOSITY = LOG_INFO | LOG_WARN | LOG_ERROR
def log(msg, msgtype=LOG_TRACE, end="\n", header=True):
if msgtype & VERBOSITY:
if header:
print(time.strftime("%Y-%m-%d %H:%M:%S")+" ["+LOGMSG_TYPES[msgtype]+"] "+msg, end=end)
else:
print(msg, end=end)
class Node:
def __init__(self, pubkey, member=False, uid="", written_on=None):
......@@ -67,9 +76,12 @@ Default options:
-M img/logo-g1.png""")
exit()
if "-v" in sys.argv:
VERBOSITY |= LOG_TRACE
# Initialize
if not "-s" in sys.argv:
os.system("duniter stop")
log(subprocess.run(["duniter", "stop"], stdout=subprocess.PIPE).stdout.decode("utf-8"))
outdata_wot = {"nodes":[], "edges":[]}
outdata_stats = {"stats":{}, "instance":{"software": "wotmap", "version": VERSION, "working": True, "maintainers": [], "custom": {}}}
......@@ -169,16 +181,16 @@ Default options:
if download_avatars:
if not avatar_exists or os.path.getmtime(avatar_path) < avatars_max_age:
try:
log("Download avatar: " + node.pubkey, " ")
log("Download avatar: " + node.pubkey, end=" ")
response = urllib.request.urlopen(url_es+"/user/profile/"+node.pubkey+"/_image/avatar.png")
f = open(avatar_path, "wb")
f.write(response.read())
f.close()
log("OK")
log("OK", header=False)
avatar_url = avatars_url_path+"/"+node.pubkey+".png"
except urllib.error.HTTPError:
avatar_url = avatars_default_url_path
log("ERR")
log("ERR", header=False)
else:
avatar_url = avatars_url_path+"/"+node.pubkey+".png"
elif avatar_exists:
......@@ -235,7 +247,7 @@ Default options:
membership = clusters.membership
nb_communities = max(membership)+1
outdata_stats["stats"]["total_communities"] = nb_communities
log('> Total communities = ' + str(nb_communities))
log('> Total communities = ' + str(nb_communities), LOG_INFO)
log("Updating referents and communities...")
crit_referent = math.ceil((nb_members+1) ** (1/STEPMAX))
......@@ -277,4 +289,5 @@ Default options:
outfile_stats.close()
if not "-s" in sys.argv:
os.system("duniter start")
log(subprocess.run(["duniter", "start"], stdout=subprocess.PIPE).stdout.decode("utf-8"))
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