mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +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
|
#!/usr/bin/env python
|
||||||
|
|
||||||
# Start listener, just for testing
|
import os, sys, argparse
|
||||||
import os, sys
|
|
||||||
#import logging
|
#import logging
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
import cfg
|
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"))
|
sys.path.append(os.path.join(cfg.file_root, "vendor"))
|
||||||
|
|
||||||
import cherrypy
|
import cherrypy
|
||||||
|
from cherrypy import _cpserver
|
||||||
|
from cherrypy.process.plugins import Daemonizer
|
||||||
|
Daemonizer(cherrypy.engine).subscribe()
|
||||||
|
|
||||||
import plugin_mount
|
import plugin_mount
|
||||||
from util import *
|
from util import *
|
||||||
from logger import Logger
|
from logger import Logger
|
||||||
@ -96,7 +99,24 @@ tools.staticfile.on = True
|
|||||||
tools.staticfile.filename = "{fileroot}/static/theme/favicon.ico"
|
tools.staticfile.filename = "{fileroot}/static/theme/favicon.ico"
|
||||||
""".format(fileroot=cfg.file_root))
|
""".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():
|
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)
|
os.chdir(cfg.file_root)
|
||||||
cherrypy.config.update({'error_page.404': error_page_404})
|
cherrypy.config.update({'error_page.404': error_page_404})
|
||||||
cherrypy.config.update({'error_page.500': error_page_500})
|
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