refactor: different scripts, working as not-unit
This commit is contained in:
parent
0f49adebe1
commit
20f139fc76
19
main.sh
19
main.sh
|
@ -1,19 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
/usr/bin/pwd
|
|
||||||
|
|
||||||
$str=`/usr/bin/diff --exclude=multi-user.target.wants -r ./services ~/.config/systemd/user`
|
|
||||||
|
|
||||||
echo $str
|
|
||||||
|
|
||||||
# Update daemon files
|
|
||||||
#/usr/bin/cp -ur ./services/* ~/.config/systemd/user
|
|
||||||
|
|
||||||
# Daemon launching
|
|
||||||
#/usr/bin/systemctl --user daemon-reload
|
|
||||||
#/usr/bin/systemctl --user is-active wthrc.service
|
|
||||||
#/usr/bin/systemctl --user restart wthrc.service
|
|
||||||
|
|
||||||
# Wait for restart
|
|
||||||
#/usr/bin/sleep 5
|
|
||||||
|
|
||||||
/usr/bin/curl localhost:8000 > ./__data__/data.out
|
|
9
scripts/install.sh
Normal file
9
scripts/install.sh
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Update daemon files
|
||||||
|
/usr/bin/cp -ur $DIR/services/* ~/.config/systemd/user
|
||||||
|
|
||||||
|
# Daemon launch
|
||||||
|
/usr/bin/systemctl --user daemon-reload
|
||||||
|
/usr/bin/systemctl --user enable wthrc.service
|
||||||
|
echo "Done installer"
|
3
scripts/main.sh
Executable file
3
scripts/main.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
/usr/bin/curl localhost:8000 > ./__data__/data.out
|
5
scripts/runner.sh
Normal file
5
scripts/runner.sh
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Launch daemon
|
||||||
|
/usr/bin/systemctl --user restart wthrc.service
|
||||||
|
echo "Done runner"
|
|
@ -1,11 +1,11 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Weather collection service
|
Description=Weather collection service
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
WorkingDirectory=/home/citrullux/ModernOSLabs/src
|
||||||
ExecStart=/usr/bin/python3 /home/citrullux/ModernOSLabs/src/main.py
|
ExecStart=/usr/bin/python3 /home/citrullux/ModernOSLabs/src/main.py
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=default.target
|
14
src/installer.py
Normal file
14
src/installer.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import filecmp
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
|
def install():
|
||||||
|
projectDir="/home/citrullux/ModernOSLabs"
|
||||||
|
delivered=filecmp.cmp(projectDir+"/services/wthrc.service", "/home/citrullux/.config/systemd/user/wthrc.service", shallow=True)
|
||||||
|
if not delivered:
|
||||||
|
os.environ["DIR"]=projectDir
|
||||||
|
subprocess.call(["/usr/bin/sh", projectDir+"/scripts/install.sh"])
|
||||||
|
subprocess.call(["/usr/bin/sh", projectDir+"/scripts/runner.sh"])
|
||||||
|
sleep(5)
|
|
@ -1,3 +1,5 @@
|
||||||
from server import weather_run
|
from server import weather_run
|
||||||
|
from installer import install
|
||||||
|
|
||||||
|
install()
|
||||||
weather_run()
|
weather_run()
|
||||||
|
|
|
@ -3,7 +3,7 @@ import urllib.request
|
||||||
|
|
||||||
|
|
||||||
@cache
|
@cache
|
||||||
def weather_handler(date: str):
|
def weather_handler(date: str) -> dict:
|
||||||
# print(date)
|
# print(date)
|
||||||
# Request variables
|
# Request variables
|
||||||
api_link = "https://api.open-meteo.com/v1/forecast?"
|
api_link = "https://api.open-meteo.com/v1/forecast?"
|
||||||
|
@ -26,5 +26,5 @@ def weather_handler(date: str):
|
||||||
+ "&forecast_days="
|
+ "&forecast_days="
|
||||||
+ days
|
+ days
|
||||||
)
|
)
|
||||||
raw_data = urllib.request.urlopen(url).read()
|
raw_data = urllib.request.urlopen(url, timeout=10).read()
|
||||||
return raw_data
|
return raw_data
|
||||||
|
|
Loading…
Reference in New Issue
Block a user