-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch Kolibri server start to a separate persistent foreground service #52
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9ed4cde
Slight refactor and cleanup, and consolidating Android-specific code.
jamalex 08d865c
Switch Kolibri server start to a separate persistent foreground service
jamalex 3fc3967
Merge branch 'develop' of github.com:learningequality/kolibri-install…
jamalex ec341bc
Pass version name in via service arguments
jamalex 6b71325
Add extra_build_options for configuring service
jamalex 96290bd
Add custom settings file and have it never expire the session
jamalex ffde26a
Copy pre-migrated DB into Kolibri data directory to speed up startup
jamalex 006b56f
Add SDK version to project info
jamalex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PORT = 8080 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import os | ||
import tempfile | ||
|
||
from kolibri.deployment.default.settings.base import * | ||
|
||
SESSION_EXPIRE_AT_BROWSER_CLOSE = False | ||
SESSION_COOKIE_AGE = 52560000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import json | ||
import logging | ||
import os | ||
import shutil | ||
import sys | ||
|
||
# initialize logging before loading any third-party modules, as they may cause logging to get configured. | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
import pew | ||
import pew.ui | ||
|
||
logging.info("Entering server.py...") | ||
|
||
script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
sys.path.append(script_dir) | ||
sys.path.append(os.path.join(script_dir, "kolibri", "dist")) | ||
|
||
os.environ["DJANGO_SETTINGS_MODULE"] = "kolibri_app_settings" | ||
|
||
# TODO: before shipping the app, make this contingent on debug vs production mode | ||
os.environ["KOLIBRI_RUN_MODE"] = "pew-dev" | ||
|
||
def start_django(port): | ||
|
||
from kolibri.utils.cli import main | ||
|
||
logging.info("Starting server...") | ||
|
||
main(["start", "--foreground", "--port={port}".format(port=port)]) | ||
|
||
|
||
if pew.ui.platform == "android": | ||
|
||
from jnius import autoclass | ||
|
||
service_args = json.loads(os.environ.get("PYTHON_SERVICE_ARGUMENT") or "{}") | ||
|
||
service = autoclass('org.kivy.android.PythonService').mService | ||
File = autoclass("java.io.File") | ||
Timezone = autoclass("java.util.TimeZone") | ||
AndroidString = autoclass('java.lang.String') | ||
Drawable = autoclass("{}.R$drawable".format(service.getPackageName())) | ||
Context = autoclass('android.content.Context') | ||
Intent = autoclass('android.content.Intent') | ||
PendingIntent = autoclass('android.app.PendingIntent') | ||
NotificationBuilder = autoclass('android.app.Notification$Builder') | ||
Notification = autoclass('android.app.Notification') | ||
|
||
def make_service_foreground(title, message): | ||
PythonActivity = autoclass('org.kivy.android.PythonActivity') | ||
app_context = service.getApplication().getApplicationContext() | ||
notification_builder = NotificationBuilder(app_context) | ||
notification_builder.setContentTitle(AndroidString(title)) | ||
notification_builder.setContentText(AndroidString(message)) | ||
notification_intent = Intent(app_context, PythonActivity) | ||
notification_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) | ||
notification_intent.setAction(Intent.ACTION_MAIN) | ||
notification_intent.addCategory(Intent.CATEGORY_LAUNCHER) | ||
intent = PendingIntent.getActivity(service, 0, notification_intent, 0) | ||
notification_builder.setContentIntent(intent) | ||
notification_builder.setSmallIcon(Drawable.icon) | ||
notification_builder.setAutoCancel(True) | ||
new_notification = notification_builder.getNotification() | ||
service.startForeground(1, new_notification) | ||
|
||
os.environ["KOLIBRI_HOME"] = service_args["HOME"] | ||
|
||
# copy an empty pre-migrated database into the Kolibri data directory to speed up startup | ||
DB_TEMPLATE_PATH = "db.sqlite3.empty" | ||
DB_PATH = os.path.join(os.environ["KOLIBRI_HOME"], "db.sqlite3") | ||
if not os.path.exists(DB_PATH) and os.path.exists(DB_TEMPLATE_PATH): | ||
if not os.path.exists(os.environ["KOLIBRI_HOME"]): | ||
os.makedirs(os.environ["KOLIBRI_HOME"]) | ||
shutil.copyfile(DB_TEMPLATE_PATH, DB_PATH) | ||
|
||
# store the version name into an envvar to be picked up by Kolibri | ||
os.environ["KOLIBRI_APK_VERSION_NAME"] = service_args["VERSION"] | ||
|
||
os.environ["TZ"] = Timezone.getDefault().getDisplayName() | ||
os.environ["LC_ALL"] = "en_US.UTF-8" | ||
|
||
logging.info("Home folder: {}".format(os.environ["KOLIBRI_HOME"])) | ||
logging.info("Timezone: {}".format(os.environ["TZ"])) | ||
|
||
make_service_foreground("Kolibri is running...", "Click here to resume.") | ||
|
||
start_django(service_args["PORT"]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
w00t!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wait... it escalated from there! Additional PR incoming.