mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-04 08:13:38 +00:00
daemonize
This commit is contained in:
parent
d3a2fbc05e
commit
ce4b594f65
24
plinth.py
24
plinth.py
@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Start listener, just for testing
|
||||
import os, sys
|
||||
import os, sys, argparse
|
||||
#import logging
|
||||
from gettext import gettext as _
|
||||
import cfg
|
||||
@ -9,6 +8,10 @@ if not os.path.join(cfg.file_root, "vendor") in sys.path:
|
||||
sys.path.append(os.path.join(cfg.file_root, "vendor"))
|
||||
|
||||
import cherrypy
|
||||
from cherrypy import _cpserver
|
||||
from cherrypy.process.plugins import Daemonizer
|
||||
Daemonizer(cherrypy.engine).subscribe()
|
||||
|
||||
import plugin_mount
|
||||
from util import *
|
||||
from logger import Logger
|
||||
@ -96,7 +99,24 @@ tools.staticfile.on = True
|
||||
tools.staticfile.filename = "{fileroot}/static/theme/favicon.ico"
|
||||
""".format(fileroot=cfg.file_root))
|
||||
|
||||
def parse_arguments():
|
||||
parser = argparse.ArgumentParser(description='Plinht web interface for the FreedomBox.')
|
||||
parser.add_argument('--pidfile', default="",
|
||||
help='specify a file in which the server may write its pid')
|
||||
args=parser.parse_args()
|
||||
if args.pidfile:
|
||||
cfg.pidfile = args.pidfile
|
||||
|
||||
def setup():
|
||||
parse_arguments()
|
||||
|
||||
try:
|
||||
if cfg.pidfile:
|
||||
from cherrypy.process.plugins import PIDFile
|
||||
PIDFile(cherrypy.engine, cfg.pidfile).subscribe()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
os.chdir(cfg.file_root)
|
||||
cherrypy.config.update({'error_page.404': error_page_404})
|
||||
cherrypy.config.update({'error_page.500': error_page_500})
|
||||
|
||||
38
share/init.d/plinth
Executable file
38
share/init.d/plinth
Executable file
@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
# This file is /etc/init.d/plinth
|
||||
DAEMON=/usr/bin/plinth.py
|
||||
PID_FILE=/var/run/plinth.pid
|
||||
|
||||
start_plinth (){
|
||||
if [ -f $PID_FILE ]; then
|
||||
echo Already running with a pid of `cat $PID_FILE`.
|
||||
else
|
||||
$DAEMON --pidfile=$PID_FILE
|
||||
fi
|
||||
}
|
||||
|
||||
stop_plinth () {
|
||||
if [ -f $PID_FILE ]; then
|
||||
kill -15 `cat $PID_FILE`
|
||||
rm -rf $PID_FILE
|
||||
else
|
||||
echo "No pid file at $PID_FILE suggests plinth is not running."
|
||||
fi
|
||||
}
|
||||
|
||||
test -x $DAEMON || exit 0
|
||||
case "$1" in
|
||||
start)
|
||||
echo "Starting Plinth."
|
||||
start_plinth
|
||||
;;
|
||||
stop)
|
||||
echo "Stoping Plinth."
|
||||
stop_plinth
|
||||
;;
|
||||
restart)
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
|
||||
esac
|
||||
Loading…
x
Reference in New Issue
Block a user