Updated docker files
This commit is contained in:
24
compose.yml
24
compose.yml
@ -1,8 +1,28 @@
|
||||
services:
|
||||
airwatchConnector:
|
||||
sync:
|
||||
image: emitlinks/airwatchConnector
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./conf:/airwatchConnector/conf
|
||||
- ./certs:/airwatchConnector/certs
|
||||
- ./logs:/airwatchConnector/logs
|
||||
- ./logs:/airwatchConnector/logs
|
||||
healthcheck:
|
||||
test: if [ -f $(ls /airwatchConnector/*_SyncGLPI.lock) ]; then exit 0; else exit 1; fi
|
||||
interval: 5m
|
||||
start_period: 3h
|
||||
environment:
|
||||
TASK: "syncGLPI"
|
||||
|
||||
stagingAssignment:
|
||||
image: emitlinks/airwatchConnector
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./conf:/airwatchConnector/conf
|
||||
- ./certs:/airwatchConnector/certs
|
||||
- ./logs:/airwatchConnector/logs
|
||||
healthcheck:
|
||||
test: if [ -f $(ls /airwatchConnector/*_StagingUserAssignation.lock) ]; then exit 0; else exit 1; fi
|
||||
interval: 15s
|
||||
start_period: 5m
|
||||
environment:
|
||||
TASK: "stagingAssignment"
|
||||
@ -1,11 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
python3 /services.py
|
||||
|
||||
systemctl daemon-reload
|
||||
|
||||
systemctl enable *-sync.timer *-staging.timer
|
||||
|
||||
systemctl start *-sync.timer *-staging.timer
|
||||
|
||||
tail -f /dev/null
|
||||
12
dockerfile
12
dockerfile
@ -1,10 +1,10 @@
|
||||
FROM debian
|
||||
FROM python
|
||||
RUN <<-EOF
|
||||
apt-get update
|
||||
apt-get install -y systemd python3 python3-cryptography python3-requests python3-toml
|
||||
apt-get install -y python3-cryptography python3-requests python3-toml
|
||||
EOF
|
||||
ADD scripts\* /airwatchConnector
|
||||
ADD services.py /
|
||||
ADD create_services.sh /
|
||||
RUN chmod u+x /create_services.sh
|
||||
ENTRYPOINT ["/create_services.sh"]
|
||||
ADD pre-start.py /
|
||||
ADD start.sh /
|
||||
RUN chmod u+x /start.sh
|
||||
ENTRYPOINT ["/start.sh"]
|
||||
26
pre-start.py
Normal file
26
pre-start.py
Normal file
@ -0,0 +1,26 @@
|
||||
import os
|
||||
import toml
|
||||
|
||||
baseDir = "/airwatchConnector"
|
||||
logDir = f"{baseDir}/logs"
|
||||
confDir = f"{baseDir}/conf"
|
||||
confFiles = os.listdir(confDir)
|
||||
|
||||
# On récupère que les fichiers .conf
|
||||
confFiles = [conf for conf in confFiles if os.path.isfile(f"{confDir}/{conf}") and not conf.endswith(".conf")]
|
||||
|
||||
for conf in confFiles:
|
||||
# On forme un nom à partir du nom du fichier de conf sans l'extension
|
||||
# et on enlève les espaces
|
||||
confName = conf[:5].replace(' ', '')
|
||||
|
||||
with open(f"{confDir}/{conf}", "r") as f:
|
||||
settings = toml.load(f)
|
||||
|
||||
# Create log folder
|
||||
if(settings["LOGS"]["Enabled"]):
|
||||
logPath = settings["LOGS"].get(Path)
|
||||
if not os.path.exists(f"{logDir}/{logPath}"):
|
||||
os.makedirs(f"{logDir}/{logPath}")
|
||||
|
||||
|
||||
75
services.py
75
services.py
@ -1,75 +0,0 @@
|
||||
import os
|
||||
import toml
|
||||
|
||||
baseDir = "/airwatchConnector"
|
||||
logDir = f"{baseDir}/logs"
|
||||
confDir = f"{baseDir}/conf"
|
||||
confFiles = os.listdir(confDir)
|
||||
|
||||
# On récupère que les fichiers .conf
|
||||
confFiles = [conf for conf in confFiles if os.path.isfile(f"{confDir}/{conf}") and not conf.endswith(".conf")]
|
||||
|
||||
for conf in confFiles:
|
||||
# On forme un nom à partir du nom du fichier de conf sans l'extension
|
||||
# et on enlève les espaces
|
||||
confName = conf[:5].replace(' ', '')
|
||||
|
||||
with open(f"{confDir}/{conf}", "r") as f:
|
||||
settings = toml.load(f)
|
||||
|
||||
# Create log folder
|
||||
if(settings["LOGS"]["Enabled"]):
|
||||
logPath = settings["LOGS"].get(Path)
|
||||
if not os.path.exists(f"{logDir}/{logPath}"):
|
||||
os.makedirs(f"{logDir}/{logPath}")
|
||||
|
||||
|
||||
with open(f"/etc/systemd/system/{confName}-sync.service", "w") as f:
|
||||
f.write(f"""[Unit]
|
||||
Description=Script Airwatch pour la synchronisation des données Airwatch et GLPI.
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
WorkingDirectory=/airwatchConnector
|
||||
ExecStart=/airwatchConnector/syncGLPI.py -c {confDir}/{conf} -s -f
|
||||
User=root
|
||||
""")
|
||||
|
||||
with open(f"/etc/systemd/system/{confName}-sync.timer", "w") as f:
|
||||
f.write(f"""[Unit]
|
||||
Description=Script Airwatch pour la synchronisation des données Airwatch et GLPI.
|
||||
|
||||
[Timer]
|
||||
OnUnitInactiveSec=1h
|
||||
AccuracySec=1us
|
||||
Unit={confName}-sync.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
""")
|
||||
|
||||
with open(f"/etc/systemd/system/{confName}-staging.service", "w") as f:
|
||||
f.write(f"""[Unit]
|
||||
Description=Script qui assigne les appareils en staging aux utilisateurs en se basant sur GLPI.
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
WorkingDirectory=/airwatchConnector
|
||||
ExecStart=/airwatchConnector/StagingUserAssignation.py -c {confDir}/{conf} -s -f
|
||||
User=root
|
||||
""")
|
||||
|
||||
with open(f"/etc/systemd/system/{confName}-staging.timer", "w") as f:
|
||||
f.write(f"""[Unit]
|
||||
Description=Script qui assigne les appareils en staging aux utilisateurs en se basant sur GLPI.
|
||||
|
||||
[Timer]
|
||||
OnUnitInactiveSec=1m
|
||||
AccuracySec=1us
|
||||
Unit={confName}-staging.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
""")
|
||||
|
||||
|
||||
38
start.sh
Normal file
38
start.sh
Normal file
@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
python /pre-start.py
|
||||
|
||||
if [ $CONF != '' ]; then
|
||||
case $TASK in
|
||||
|
||||
syncGLPI)
|
||||
python /airwatchConnector/sync.py -c $CONF -f
|
||||
;;
|
||||
|
||||
stagingAssignment)
|
||||
python /airwatchConnector/stagingUserAssignation.py -c $CONF -f
|
||||
;;
|
||||
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
else
|
||||
confFiles = $(ls /airwatchConnector/conf/*.conf)
|
||||
for CONF in $confFiles; do
|
||||
case $TASK in
|
||||
|
||||
syncGLPI)
|
||||
python /airwatchConnector/sync.py -c $CONF -for
|
||||
;;
|
||||
|
||||
stagingAssignment)
|
||||
python /airwatchConnector/stagingUserAssignation.py -c $CONF -f
|
||||
;;
|
||||
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
Reference in New Issue
Block a user