top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to make a python script a service

+3 votes
66 views

I have a python script that is currently run from cron. We want to make it into a service so it can be controlled with service start/stop/restart.
Can anyone point me at site that has instructions on how to do this?

posted Dec 9, 2013 by Deepankar Dubey

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button
The keyword your looking for here is "daemonize".
I don't just want to make it into a daemon - I want to control it with the service command.

1 Answer

+2 votes

Try to use this
http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/

it allows you start/stop/restart the script using the following commands.

python myscript.py start
python myscript.py stop
python myscript.py restart
answer Dec 9, 2013 by Sumit Pokharna
Turn it into a daemon as described, then take a look at the existing scripts in /etc/init.d/. There might even be a template in there iirc. Your script will likely be a simple wrapper around your daemonized python program.

After that, just do a "chkconfig --add “ where myscript is the name of your script in /etc/init.d.
Similar Questions
0 votes

I am running a python script and it will create a file name like filename0.0.0 and If I run it again then new file will create one more like filename0.0.1......
my code is-

i = 0
for i in range(1000):
 try:
 with open('filename%d.%d.%d.json'%(0,0,i,)): pass
 continue
 except IOError:
 dataFile = file('filename%d.%d.%d.json'%(0,0,i,), 'a+')
 break

But It will take more time after creating many files, So i want to store value of last var "i" in a variable so that when I run my script again then I can use it. for example-
my last created file is filename0.0.27 then it should store 27 in a variable and when i run again then new file should be created 0.0.28 according to last value "27", so that i could save time and it can create file fast..

0 votes

How to run a python script twice randomly in a day? Actually I want to run my script randomly in a day and twice only. Please help me.. how is it possible.

0 votes

How to read/load the cmake file in python and access its elements. I have a scenario, where i need to load the make file and access its elements. I have tried reading the make file as text file and parsing it,but its not the ideal solution. Please let me know how to load the .mk file and access its elements in python.

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...