If docker service is not running, try to start it

This commit is contained in:
Micah Lee 2020-03-12 16:00:30 -07:00
parent 7e398e2b28
commit 0b1cd9e9ef
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
3 changed files with 33 additions and 1 deletions

View file

@ -40,7 +40,7 @@ class Application(QtWidgets.QApplication):
@click.command() @click.command()
@click.option("--custom-container") # Use this container instead of flmcode/dangerzone @click.option("--custom-container") # Use this container instead of flmcode/dangerzone
@click.argument("filename", required=False) @click.argument("filename", required=False)
def main(custom_container, filename): def main(custom_container, filename):
click.echo(f"dangerzone {dangerzone_version}") click.echo(f"dangerzone {dangerzone_version}")
@ -75,6 +75,9 @@ def main(custom_container, filename):
if not global_common.ensure_user_is_in_docker_group(): if not global_common.ensure_user_is_in_docker_group():
click.echo("Failed to add user to docker group") click.echo("Failed to add user to docker group")
return return
if not global_common.ensure_docker_service_is_started():
click.echo("Failed to start docker service")
return
# See if we need to install Docker... # See if we need to install Docker...
if (platform.system() == "Darwin" or platform.system() == "Windows") and ( if (platform.system() == "Darwin" or platform.system() == "Windows") and (

View file

@ -19,6 +19,7 @@ elif platform.system() == "Linux":
from xdg.DesktopEntry import DesktopEntry from xdg.DesktopEntry import DesktopEntry
from .settings import Settings from .settings import Settings
from .docker_installer import is_docker_ready
class GlobalCommon(object): class GlobalCommon(object):
@ -404,6 +405,31 @@ class GlobalCommon(object):
return True return True
def ensure_docker_service_is_started(self):
if not is_docker_ready(self):
message = "<b>Dangerzone requires Docker.</b><br><br>Docker should be installed, but it looks like it's not running in the background.<br><br>Click Ok to try starting the docker service. You will have to type your login password."
if Alert(self, message).launch():
p = subprocess.run(
[
"/usr/bin/pkexec",
self.get_resource_path("enable_docker_service.sh"),
]
)
if p.returncode == 0:
# Make sure docker is now ready
if is_docker_ready(self):
return True
else:
message = "Restarting docker appeared to work, but the service still isn't responding, quitting."
Alert(self, message).launch()
else:
message = "Failed to start the docker service, quitting."
Alert(self, message).launch()
return False
return True
def get_subprocess_startupinfo(self): def get_subprocess_startupinfo(self):
if platform.system() == "Windows": if platform.system() == "Windows":
startupinfo = subprocess.STARTUPINFO() startupinfo = subprocess.STARTUPINFO()

3
share/enable_docker_service.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
/usr/bin/systemctl restart docker
/usr/bin/systemctl enable docker