I have two scripts which together allow me to receive and answer phone calls over serial. The first is what I want to run as a service in the background it checks if there is a RING signal and if there is then open a terminal window with the second script running.
They both use python3, the first script is:
while True:
if (ser.inWaiting() > 0):
x = ser.readline()
if (x == b'RING\r\r\n'):
os.system("gnome-terminal -- python3 /home/user/answer.py")
exit()
The main part of the second is:
os.system("clear")
print("Incoming Call")
PU = input("Press Enter To Pick Up")
send_at('ATA' + ';','OK',1)
os.system("clear")
print("ON CALL")
HU = input("Press Enter To Hang Up")
send_at("AT+CHUP\r\n" + ';','OK',1)
os.system("clear")
print('Call Ended')
time.sleep(3)
os.system("clear")
os.system("gnome-terminal -- python3 /home/user/ring.py")
os.system("exit")
If I run the first in an open terminal just as "python3 ring.py" it works fine but leaves me with a constant open terminal.
What I want is to run Ring.py as a service or a background process that just launches Answer.py as it's called.
I tried using a .service file, enabled and started it, htop showed that it was running Ring.py but it wouldn't launch Answer.py in a terminal window. There's no error code it just doesn't show up.
This is the service file:
[Unit]
Description=Detect Incoming Calls
[Service]
Type=simple
User='my username'
ExecStart= /usr/bin/python3 /home/user/Ring.py
Restart=always
[Install]
WantedBy=multi-user.target
How can I get this to work the way I want? Or what am I doing wrong?
systemctl --user start service-name
to make use of the running graphical user session so thegnome-terminal
can launch? ... A system service is not what you want. – Raffa Jul 03 '23 at 07:35=
sign likeExecStart= /usr/bin/python3 ...
should beExecStart=/usr/bin/python3 ...
– Raffa Jul 03 '23 at 09:25