Onionr/src/onionrcommands/restartonionr.py

57 lines
1.7 KiB
Python
Raw Normal View History

2019-09-20 16:25:12 +00:00
"""
Onionr - Private P2P Communication
Command to restart Onionr
"""
"""
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/>.
"""
import time
import os
import subprocess
import platform
from etc import onionrvalues
2019-11-16 04:18:38 +00:00
from etc import cleanup
2019-09-20 16:25:12 +00:00
from onionrutils import localcommand
import logger
2019-09-29 21:32:46 +00:00
import filepaths
2019-09-20 16:25:12 +00:00
from . import daemonlaunch
SCRIPT_NAME = os.path.dirname(os.path.realpath(__file__)) + f'/../../{onionrvalues.SCRIPT_NAME}'
def restart():
logger.info('Restarting Onionr', terminal=True)
# On platforms where we can, fork out to prevent locking
try:
pid = os.fork()
if pid != 0: return
2019-11-16 04:18:38 +00:00
except (AttributeError, OSError) as e:
if platform.platform() != 'Windows':
logger.warn('Could not fork on restart')
2019-09-20 16:25:12 +00:00
daemonlaunch.kill_daemon()
while localcommand.local_command('ping', maxWait=8) == 'pong!':
time.sleep(0.3)
time.sleep(15)
while os.path.exists(filepaths.private_API_host_file) or os.path.exists(filepaths.daemon_mark_file):
2019-09-29 21:32:46 +00:00
time.sleep(1)
2019-11-16 04:18:38 +00:00
cleanup.delete_run_files()
2019-09-20 16:25:12 +00:00
subprocess.Popen([SCRIPT_NAME, 'start'])
restart.onionr_help = 'Gracefully restart Onionr'