1

Summary:

A python script using apshceduler fails to load as service with exit code 203/EXEC. Important to note that same script designed to run every 10 seconds using while True: syntax runs very well as daemon (service).

Details

I wrote a simple test.py program. It appends some a.txt file every 10 seconds with "some" string. When I try to run it as daemon service as it comes out with error code. . In itself without using it as daemon (service) it works fine. Also if I don't use apscheduler in writing the test.py file then the service runs smoothly. I will put all the code here for details including the systemctl status

Code

test.py file

import os, glob, shutil
from datetime import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
sched = BlockingScheduler()
def test():
    appendFile = open(r'/home/sangharsh/code/a.txt', 'a')
    appendFile.write("Jai Bhim \n" )
    appendFile.close()
sched.add_job(test, 'interval', seconds=10)

sched.start()

Its located @ - /home/sangharsh/code/workingWithFiles/ To run it as daemon I create service file -

service config file

[Unit]
Description=Test Service
After=multi-user.target
Conflicts=getty@tty1.service

[Service]
Type=simple
ExecStart=/usr/bin/env python3 /home/sangharsh/code/workingWithFiles/test.py
StandardInput=tty-force

[Install]
WantedBy=multi-user.target

This file is located @ - /lib/systemd/system/

I restart the daemon-

sudo systemctl daemon-reload

Then enable the test.service file -

sudo systemctl enable test.service

and to start the test.service

sudo systemctl start test.service

and to scheck the status

sudo systemctl status test.service

The systemctl status shows:

● test.service - Test Service
   Loaded: loaded (/lib/systemd/system/test.service; enabled; vendor preset: ena
   Active: failed (Result: exit-code) since Tue 2019-07-09 23:28:10 IST; 13s ago
  Process: 5272 ExecStart=/usr/bin/env python3 /home/sangharsh/code/workingWithF
 Main PID: 5272 (code=exited, status=1/FAILURE)

Jul 09 23:28:10 sangharsh-HP-240-G4-Notebook-PC systemd[1]: Started Test Service
Jul 09 23:28:10 sangharsh-HP-240-G4-Notebook-PC systemd[1]: test.service: Main p
Jul 09 23:28:10 sangharsh-HP-240-G4-Notebook-PC systemd[1]: test.service: Failed

I referred this question. I tried the options but it doesn't help. And this is not much applicable as it has permission issues.

1: https://unix.stackexchange.com/q/472950/361166 ```

Please guide.

sangharsh
  • 148
  • 1
  • 10

0 Answers0