Detach program by argv.
(path, argv, logfile=None, pidfile=None, uid=None,
gid=None, umask=None, workdir=None, fake=False, app=None,
executable=None, hostname=None)
| 106 | |
| 107 | |
| 108 | def detach(path, argv, logfile=None, pidfile=None, uid=None, |
| 109 | gid=None, umask=None, workdir=None, fake=False, app=None, |
| 110 | executable=None, hostname=None): |
| 111 | """Detach program by argv.""" |
| 112 | fake = 1 if C_FAKEFORK else fake |
| 113 | # `detached()` will attempt to touch the logfile to confirm that error |
| 114 | # messages won't be lost after detaching stdout/err, but this means we need |
| 115 | # to pre-format it rather than relying on `setup_logging_subsystem()` like |
| 116 | # we can elsewhere. |
| 117 | logfile = node_format(logfile, hostname) |
| 118 | with detached(logfile, pidfile, uid, gid, umask, workdir, fake, |
| 119 | after_forkers=False): |
| 120 | try: |
| 121 | if executable is not None: |
| 122 | path = executable |
| 123 | os.execv(path, [path] + argv) |
| 124 | return EX_OK |
| 125 | except Exception: # pylint: disable=broad-except |
| 126 | if app is None: |
| 127 | from celery import current_app |
| 128 | app = current_app |
| 129 | app.log.setup_logging_subsystem( |
| 130 | 'ERROR', logfile, hostname=hostname) |
| 131 | logger.critical("Can't exec %r", ' '.join([path] + argv), |
| 132 | exc_info=True) |
| 133 | return EX_FAILURE |
| 134 | |
| 135 | |
| 136 | @click.command(cls=CeleryDaemonCommand, |
no test coverage detected