2019-12-19 10:34:19 +00:00
|
|
|
"""Onionr - Private P2P Communication.
|
2019-09-20 16:25:12 +00:00
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
Command to restart Onionr
|
2019-09-20 16:25:12 +00:00
|
|
|
"""
|
2019-12-19 10:34:19 +00:00
|
|
|
import time
|
|
|
|
import os
|
|
|
|
import subprocess # nosec
|
|
|
|
|
|
|
|
from etc import onionrvalues
|
|
|
|
from etc import cleanup
|
|
|
|
from onionrutils import localcommand
|
|
|
|
import logger
|
|
|
|
import filepaths
|
|
|
|
|
|
|
|
from . import daemonlaunch
|
2019-09-20 16:25:12 +00:00
|
|
|
"""
|
|
|
|
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/>.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
SCRIPT_NAME = os.path.dirname(os.path.realpath(
|
|
|
|
__file__)) + f'/../../{onionrvalues.SCRIPT_NAME}'
|
2019-09-20 16:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def restart():
|
2019-12-19 10:34:19 +00:00
|
|
|
"""Tell the Onionr daemon to restart."""
|
2019-09-20 16:25:12 +00:00
|
|
|
logger.info('Restarting Onionr', terminal=True)
|
2019-11-01 18:35:28 +00:00
|
|
|
|
|
|
|
# On platforms where we can, fork out to prevent locking
|
|
|
|
try:
|
|
|
|
pid = os.fork()
|
2019-12-19 10:34:19 +00:00
|
|
|
if pid != 0:
|
|
|
|
return
|
|
|
|
except (AttributeError, OSError):
|
2020-02-06 02:31:38 +00:00
|
|
|
logger.warn('Could not fork on restart')
|
2020-06-27 23:03:20 +00:00
|
|
|
with open(filepaths.restarting_indicator, 'w') as f:
|
|
|
|
f.write('t')
|
2019-09-20 16:25:12 +00:00
|
|
|
daemonlaunch.kill_daemon()
|
2020-07-17 18:49:18 +00:00
|
|
|
while localcommand.local_command('ping', max_wait=8) == 'pong!':
|
2019-09-20 16:25:12 +00:00
|
|
|
time.sleep(0.3)
|
2019-10-14 00:56:14 +00:00
|
|
|
time.sleep(15)
|
2019-12-19 10:34:19 +00:00
|
|
|
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-12-19 10:34:19 +00:00
|
|
|
|
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'])
|
|
|
|
|
2019-12-19 10:34:19 +00:00
|
|
|
|
|
|
|
restart.onionr_help = 'Gracefully restart Onionr' # type: ignore
|