데몬으로 python script 를 실행할때 직접 daemonizing 코드를 구형하여 만들었는데
python-daemon 이라는 패키지를 사용해보니 cmdline 에서 start/stop/restart 도 지원하고 filelock 도 지원한다.
쓸만해보여서 정리해둠
wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgztar zxf Python-2.7.12.tgzcd Python-2.7.12./configure --prefix=/home/apps/python2.7 --enable-unicode=ucs4 --enable-sharedmakemake installwget --no-check-certificate https://pypi.python.org/packages/25/4e/1b16cfe90856235a13872a6641278c862e4143887d11a12ac4905081197f/setuptools-28.8.0.tar.gztar zxf setuptools-28.8.0.tar.gzcd setuptools-28.8.0python2.7 setup.py buildpython2.7 setup.py installwget --no-check-certificate https://bootstrap.pypa.io/get-pip.pypython2.7 get-pip.pypip install python-daemon mkdir /daemon_samplecd /daemon_samplemkdir bin lib log runcd binvi daemon_sample.py--------------------------------------------------------------------------------------------#!/home/apps/python2.7/bin/python# -*- coding: UTF-8 -*-import timefrom daemon.runner import DaemonRunnerclass TestDaemon(object): def __init__(self): self.stdin_path = '/dev/null' self.stdout_path = '/dev/tty' self.stderr_path = '/dev/tty' self.pidfile_timeout = 0 self.pidfile_path="/usr/mgmt/apm_package_manager/run/TestDaemon.pid" def run(self): while 1: time.sleep(3)DaemonRunner(TestDaemon()).do_action()--------------------------------------------------------------------------------------------chmod 700 daemon_sample.py./daemon_sample.pyusage: test.py start|stop|restart ./daemon_sample.py startstarted with pid 24751 ./daemon_sample.py start File "./test.py", line 19, in <module> DaemonRunner(TestDaemon()).do_action() File "/home/apps/python2.7/lib/python2.7/site-packages/daemon/runner.py", line 274, in do_action func(self) File "/home/apps/python2.7/lib/python2.7/site-packages/daemon/runner.py", line 187, in _start raise errordaemon.runner.DaemonRunnerStartFailureError: PID file '/usr/mgmt/apm_package_manager/run/TestDaemon.pid' already locked'Python' 카테고리의 다른 글
| Pika Python AMQP Client Library (0) | 2017.01.31 |
|---|---|
| s3 example (0) | 2016.12.28 |
| Threading (0) | 2016.12.22 |
| pidlockfile.py for windows (0) | 2016.12.19 |
| cygwin + ssh + rsync (0) | 2016.12.10 |