daemonocle icon indicating copy to clipboard operation
daemonocle copied to clipboard

using os.mkdir() crashes ERROR: Child exited immediately with exit code 127

Open Shivaprasad2452 opened this issue 5 years ago • 1 comments

I try to create log directory, while starting the job using os.mkdir() throws ERROR: Child exited immediately with exit code 127 the following code ...

def _config_logger():
    log_dir  = os.path.join(os.getcwd() ,"logs")
    if not os.path.exists( log_dir ):
         os.mkdir( log_dir )

    logfile  = os.path.join(log_dir ,"agent.log")

    logging.basicConfig(
        filename=logfile,
        level=logging.DEBUG, format='%(asctime)s [%(levelname)s] %(message)s',
    )
 ``
def main():
    config = _load_config()

    if config:
        _config_logger()
        logging.info('Daemon is starting')

        while True:
            print("akka")
            logging.debug('Still running')
            logging.warning('warning')
            time.sleep(config['pollIntervalSecs'])

if __name__ == '__main__':
    pidfile_name = 'kooo.pid'
    pidfile_path = os.path.join(os.getcwd() ,pidfile_name)
    daemon = MyDaemon(
        worker=main,
        pidfile=pidfile_path,
        detach=True,
    )
    daemon.do_action(sys.argv[1])

Shivaprasad2452 avatar Aug 08 '19 12:08 Shivaprasad2452

Sorry for the extremely delayed response.

Try running your daemon with detach=False, and it will likely show you the error. Looking at your code, I'm pretty certain this is because your log_dir variable is os.path.join(os.getcwd(), "logs"), and daemonocle changes to the / directory by default before running the worker. So os.getcwd() returns /, and you likely don't have permission to create /logs. You can change this behavior with the workdir argument to the Daemon class.

jnrbsn avatar Jul 15 '20 02:07 jnrbsn