I'm wondering if there's somewhere in the package, an init script or something to run BTManager as a deamon ( and gives output to a log file instead of stdout ).
It's very nice to have remote access on Bittorrent, using BTManager, but you have to get phisical access to the server machine to run it (unless running "screen", but this makes no sense ).
thx.
Gis
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was having the same problem, so i went looking for an script to fork a python script as a daemon i found and edited it to work for BTmanager , below you'll vind the script , just put it in a .py file in the same dir as the main script (BTManagerServer.py and execute it instead of the main script) (called mine BTManagerDaemon.py)
class Log:
"""file like for writes with auto flush after each write
to ensure that everything is logged, even during an
unexpected exit."""
def __init__(self, f):
self.f = f
def write(self, s):
self.f.write(s)
self.f.flush()
I had the same problem as the original poster and found another solution to do the same thing as the python script mentionned above. Hopefully this might be helpful to someone :
from a terminal, instead of running BTLauncher.py, run :
nohup BTLauncher.py &
that'll prevent BTLauncher from being killed by a SIGHUP when you log out, as far as I can understand with my limited linux knowledge :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm wondering if there's somewhere in the package, an init script or something to run BTManager as a deamon ( and gives output to a log file instead of stdout ).
It's very nice to have remote access on Bittorrent, using BTManager, but you have to get phisical access to the server machine to run it (unless running "screen", but this makes no sense ).
thx.
Gis
I was having the same problem, so i went looking for an script to fork a python script as a daemon i found and edited it to work for BTmanager , below you'll vind the script , just put it in a .py file in the same dir as the main script (BTManagerServer.py and execute it instead of the main script) (called mine BTManagerDaemon.py)
[code]
#!/usr/bin/env python
###########################################################################
# configure these paths:
LOGFILE = '/var/log/pydaemon.log'
PIDFILE = '/var/run/pydaemon.pid'
###########################################################################
from btmBase.BTManagerConfig import config
import sys, os
class Log:
"""file like for writes with auto flush after each write
to ensure that everything is logged, even during an
unexpected exit."""
def __init__(self, f):
self.f = f
def write(self, s):
self.f.write(s)
self.f.flush()
def main():
sys.stdout = sys.stderr = Log(open(LOGFILE, 'a+'))
home = os.getenv('HOME')
if home:
dr = os.path.join(home, '.btmanager')
try:
os.makedirs(dr)
except OSError:
pass
config.Paths.data = dr
else:
config.Paths.data = config.Paths.base
import btmWeb.Server
if config.Limits.no_output:
from OutputSuppresser import remove
remove()
btmWeb.Server.start_server()
if __name__ == "__main__":
# do the UNIX double-fork magic
try:
pid = os.fork()
if pid > 0:
# exit first parent
sys.exit(0)
except OSError, e:
print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror)
sys.exit(1)
# decouple from parent environment
os.chdir("/") #don't prevent unmounting....
os.setsid()
os.umask(0)
# do second fork
try:
pid = os.fork()
if pid > 0:
# exit from second parent, print eventual PID before
#print "Daemon PID %d" % pid
open(PIDFILE,'w').write("%d"%pid)
sys.exit(0)
except OSError, e:
print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
sys.exit(1)
# start the daemon main loop
main()
[/code]
Hello. I should check the forums more often :)
I think I'll include this functionnality in v2, may I borrow your code? The credits file is too thin right now :)
it's not my code , i found it in a howto about running a python script as a daemon, i just edited it so it would work with BTmanager.
The script i edited came from this site :
http://homepage.hispeed.ch/py430/python/index.html
so i think you'll have to ask the owner of that site if you wan't to use the script.
Thanks!
I had the same problem as the original poster and found another solution to do the same thing as the python script mentionned above. Hopefully this might be helpful to someone :
from a terminal, instead of running BTLauncher.py, run :
nohup BTLauncher.py &
that'll prevent BTLauncher from being killed by a SIGHUP when you log out, as far as I can understand with my limited linux knowledge :)