moved daemon kill command to its own seperate file in daemonlaunch

This commit is contained in:
Kevin Froman 2020-03-19 01:43:57 -05:00
parent 1ffc899695
commit e90d7e96f4
2 changed files with 62 additions and 32 deletions

View File

@ -5,10 +5,8 @@ launch the api servers and communicator
import os
import sys
import platform
import sqlite3
from threading import Thread
from gevent import spawn
from stem.connection import IncorrectPassword
import toomanyobjs
import filenuke
@ -35,6 +33,7 @@ from .getapihost import get_api_host_until_available
from utils.bettersleep import better_sleep
from netcontroller.torcontrol.onionservicecreator import create_onion_service
from .quotes import QUOTE
from .killdaemon import kill_daemon # noqa
from utils.boxprint import bordered
from lan import LANManager
from lan.server import LANServer
@ -61,6 +60,8 @@ def _proper_shutdown():
def daemon():
"""Start the Onionr communication daemon."""
# Determine if Onionr is in offline mode.
# When offline, Onionr can only use LAN and disk transport
offline_mode = config.get('general.offline_mode', False)
if not hastor.has_tor():
@ -192,36 +193,6 @@ def _ignore_sigint(sig, frame): # pylint: disable=W0612,W0613
return
def kill_daemon():
"""Shutdown the Onionr daemon (communicator)."""
logger.warn('Stopping the running daemon...', timestamp=False,
terminal=True)
# On platforms where we can, fork out to prevent locking
try:
pid = os.fork()
if pid != 0:
return
except (AttributeError, OSError):
pass
events.event('daemon_stop')
net = NetController(config.get('client.port', 59496))
try:
spawn(
localcommand.local_command,
'/shutdownclean'
).get(timeout=5)
except sqlite3.OperationalError:
pass
net.killTor()
kill_daemon.onionr_help = "Gracefully stops the " # type: ignore
kill_daemon.onionr_help += "Onionr API servers" # type: ignore
def start(override: bool = False):
"""If no lock file, make one and start onionr.

View File

@ -0,0 +1,59 @@
"""Onionr - Private P2P Communication.
Gracefully stop Onionr daemon
"""
import sqlite3
import os
from gevent import spawn
from onionrplugins import events
from onionrutils import localcommand
import logger
from netcontroller import NetController
import config
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
def kill_daemon():
"""Shutdown the Onionr daemon (communicator)."""
config.reload()
logger.warn('Stopping the running daemon...', timestamp=False,
terminal=True)
# On platforms where we can, fork out to prevent locking
try:
pid = os.fork()
if pid != 0:
return
except (AttributeError, OSError):
pass
events.event('daemon_stop')
net = NetController(config.get('client.port', 59496))
try:
spawn(
localcommand.local_command,
'/shutdownclean'
).get(timeout=5)
except sqlite3.OperationalError:
pass
net.killTor()
kill_daemon.onionr_help = "Gracefully stops the " # type: ignore
kill_daemon.onionr_help += "Onionr API servers" # type: ignore