Skip to content

Commit 2ec7c7b

Browse files
committed
Cleanup provisioning system
1 parent 5af2f38 commit 2ec7c7b

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

provisioning/machine_config.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def access_points(configuration, loop):
5252
stopped = False
5353

5454

55-
def stop():
55+
async def stop():
5656
global stopped
5757
stopped = True
5858

@@ -114,8 +114,7 @@ def set_password(new_password, prev_set_password):
114114
): # when changing as the mirte user, there are some checks, when changing as root, no checks
115115
return
116116
print(f'Changing password to "{new_password}"')
117-
print(f'echo "{new_password}\n{new_password}" | sudo passwd mirte')
118-
o = os.system(f'echo "{new_password}\n{new_password}" | sudo passwd mirte')
117+
o = os.system(f'sudo chpasswd mirte:{new_password}')
119118
print(o)
120119

121120

provisioning/provisioning.py

+27-21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
import asyncio
44
import traceback
5+
from signal import SIGINT, SIGTERM
56

67
# Provisioning system for the Mirte sd cards.
78
# Only activate this service when you want to copy configurations from the second partition to the operating system
@@ -15,32 +16,37 @@
1516

1617
modules = [robot_config, machine_config, ssh]
1718

18-
event_loop = asyncio.get_event_loop()
1919

20-
for module in modules:
21-
try:
22-
module.start(mount_point, event_loop)
23-
except Exception as e:
24-
print(e)
25-
print(traceback.format_exc())
20+
async def stop(event_loop):
21+
for module in modules:
22+
try:
23+
await module.stop()
24+
except Exception as e:
25+
print(e)
26+
event_loop.stop()
2627

2728

28-
async def main():
29-
count = 1000
30-
while True:
31-
count += -1
32-
await asyncio.sleep(1)
3329

3430

35-
event_loop.run_until_complete(main())
31+
if __name__ == "__main__":
32+
event_loop = asyncio.get_event_loop()
3633

34+
for module in modules:
35+
try:
36+
module.start(mount_point, event_loop)
37+
except Exception as e:
38+
print(e)
39+
print(traceback.format_exc())
40+
for signal in [SIGINT, SIGTERM]:
41+
event_loop.add_signal_handler(signal,
42+
lambda: event_loop.create_task(stop(event_loop)))
3743

38-
for module in modules:
39-
try:
40-
module.stop()
41-
except Exception as e:
42-
print(e)
4344

44-
pending = asyncio.all_tasks(loop=event_loop)
45-
event_loop.run_until_complete(asyncio.gather(*pending))
46-
event_loop.close()
45+
event_loop.run_forever()
46+
47+
48+
49+
50+
pending = asyncio.all_tasks(loop=event_loop)
51+
event_loop.run_until_complete(asyncio.gather(*pending))
52+
event_loop.close()

provisioning/robot_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def on_modified(self, event):
6464
self.catch_all_handler(event)
6565

6666

67-
def stop():
67+
async def stop():
6868
observer.stop()
6969
observer.join()
7070

provisioning/ssh.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ def start(mount_point, loop):
2121
file.writelines(new_keys)
2222

2323

24-
def stop():
24+
async def stop():
2525
print("stop ssh")

0 commit comments

Comments
 (0)