0

I have a strange problem.. I've created a python script (modbus_sensor.py), which runs as a service. Modbus_sensor.py calls around 15 other python scripts by a scheduler.

When I run modbus_sensor.py like: "python modbus_sensor.py" it works fantastic and all the sub scripts are running.
But when I start the script like a service: "service modbus_daemon start", the main script starts, but it doesn't call the other scripts.

def ExecuteReadChange(sScriptName = '', sArg1 = '', sArg2 = ''):
# os.system ('sudo python ' + sScriptName + ' ' + sArg1) #Call every script

# os.system ('sudo /usr/bin/python /usr/local/bin/modbus_sensor/test.py') # returns 256
# subprocess.call('sudo python test.py', shell=True)
# subprocess.call('sudo /usr/bin/python /usr/local/bin/modbus_sensor/test.py', shell=True) # returns 1

I have tried everything like, with/without complete path.

What can be the problem?

  • 1
    Can you provide a start script of modbus_daemon (maybe problem is into the path to the python installation - try using full path to python)? Did you try to see output of service (best way is to use a logging package, but it can be done throw the stdout/stderr pipes like "/usr/bin/python modbus_sensor.py >> /tmp/modbus_sensor.log 2>&1")? – Max Vyaznikov Aug 04 '15 at 13:16
  • Hi Max, on top of every python script, I added: #!/usr/bin/env python # -*- coding: utf-8 -*- # chkconfig: 2345 95 20 When i catch the result of - os.system, it returns: 256 - subprocess.call, it returns: 1 – Gerbert van Veldhuizen Aug 04 '15 at 13:40
  • 1
    The logs contains nothing.. When i run manual with 'python modbus_sensor.py', it contains prints of the scripts. When running by daemon, it does not contain anything – Gerbert van Veldhuizen Aug 04 '15 at 14:01

1 Answers1

0

You might have to disable requiretty in your /etc/sudoers settings:

Use the visudo command to edit /etc/sudoers

Replace:

Defaults    requiretty

With:

Defaults    !requiretty
Joe Young
  • 5,749
  • 3
  • 28
  • 27