linux - Python startup script using STDOUT for outputs, using init.d method -


my environment debian jesse on embedded arm display.

i using bash script automatically launch app using init.d method. launches second python script daemon handles application on startup , reboot.

because run way best of knowledge daemon background process, , disconnects stdout , stdin python script.

the system , application single purpose, spamming console outputs background process not not problem, desired. outputs can ssh or serial console display , see live debug outputs or exceptions.

i have looked possible ways force process foreground, or redirect outputs stdout have not found definite answer when script run @ startup.

my logging file working perfect , otherwise app works in state in. when need debug stop application , run manually outputs.

i have considered using sockets redirect outputs app, , running separate script listening print console... seems less ideal , better solution might exist.

is there methods achieve or should accept this.

edit 1 (additional details)

because using multiple logs multiple processes have created logger class. stream handler uses default should sys.stderr.

import logging import logging.handlers  class loggersetup(object):      def __init__(self, logname, logfilenameandpath, logsizebytes, logfilecount):          log = logging.getlogger(logname)         log.setlevel(logging.info)          formatter = logging.formatter('%(asctime)s - %(levelname)s - ' + logname + ' - %(message)s',datefmt="%m-%d %h:%m:%s")         # add log message handler logger          if(logfilecount > 0):              filehandler = logging.handlers.rotatingfilehandler(logfilenameandpath, maxbytes=logsizebytes, backupcount=logfilecount)             log.addhandler(filehandler)             filehandler.setformatter(formatter)          consolehandler = logging.streamhandler()         log.addhandler(consolehandler)         consolehandler.setformatter(formatter)          log.info(logname + ' initialized') 

for more reference here startup script launch on boot. runs python run.py handles rest of startup process.

#!/bin/sh  ### begin init info # provides:          arcimotostart # required-start:    $remote_fs $syslog # required-stop:     $remote_fs $syslog # default-start:     2 3 4 5 # default-stop:      0 1 6 # short-description: startup script # description:       startip script points run.py ### end init info  # change next 3 lines suit install script , want call daemon=/app/run.py daemon_name=app  # add command line options daemon here daemon_opts=""  # next line determines user script runs as. # root not recommended necessary if using features in python. daemon_user=root  # process id of script when runs stored here: pidfile=/var/run/$daemon_name.pid  . /lib/lsb/init-functions  do_start () {     log_daemon_msg "starting system $daemon_name daemon"     start-stop-daemon --start --background --pidfile $pidfile --make-pidfile --user $daemon_user --chuid $daemon_user --startas $daemon -- $daemon_opts     log_end_msg $? } do_stop () {     log_daemon_msg "stopping system $daemon_name daemon"     start-stop-daemon --stop --pidfile $pidfile --retry 10     log_end_msg $? }  case "$1" in     start|stop)         do_${1}         ;;     restart|reload|force-reload)         do_stop         do_start         ;;     status)         status_of_proc "$daemon_name" "$daemon" && exit 0 || exit $?         ;;     *)         echo "usage: /etc/init.d/$daemon_name {start|stop|restart|status}"         exit 1         ;; esac exit 0 


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -