From acbcac456f4e04bfe0fac6da8a9aa38f51ede4cb Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Tue, 30 Jul 2019 00:29:26 -0400 Subject: [PATCH 1/3] Adds lbrynet.service target --- config/comment-server.target | 1 + src/server/database.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/config/comment-server.target b/config/comment-server.target index afdcc05..223a843 100644 --- a/config/comment-server.target +++ b/config/comment-server.target @@ -2,6 +2,7 @@ Description="LBRY Comment Server Watchdog" After=network.target Requires=comment-server@5921.service comment-server@5922.service comment-server@5923.service comment-server@5924.service +Wants=lbrynet.service [Install] diff --git a/src/server/database.py b/src/server/database.py index 5b56ae1..3a85e6f 100644 --- a/src/server/database.py +++ b/src/server/database.py @@ -125,14 +125,14 @@ def get_comment_ids(conn: sqlite3.Connection, claim_id: str, parent_id: str = No curs = conn.execute(""" SELECT comment_id FROM COMMENTS_ON_CLAIMS WHERE claim_id = ? AND parent_id IS NULL LIMIT ? OFFSET ? - """, (claim_id, page_size, page_size*abs(page - 1),) - ) + """, (claim_id, page_size, page_size * abs(page - 1),) + ) else: curs = conn.execute(""" SELECT comment_id FROM COMMENTS_ON_CLAIMS WHERE claim_id = ? AND parent_id = ? LIMIT ? OFFSET ? """, (claim_id, parent_id, page_size, page_size * abs(page - 1),) - ) + ) return [tuple(row)[0] for row in curs.fetchall()] @@ -175,7 +175,7 @@ def get_channel_id_from_comment_id(conn: sqlite3.Connection, comment_id: str): channel = conn.execute(""" SELECT channel_id, channel_name FROM COMMENTS_ON_CLAIMS WHERE comment_id = ? """, (comment_id,) - ).fetchone() + ).fetchone() return dict(channel) if channel else dict() From c3a4eef9ee1a22ee2f069ec6460a0641506f9f6d Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Tue, 30 Jul 2019 01:15:04 -0400 Subject: [PATCH 2/3] Fixes formatting --- src/server/database.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/server/database.py b/src/server/database.py index 3a85e6f..5b56ae1 100644 --- a/src/server/database.py +++ b/src/server/database.py @@ -125,14 +125,14 @@ def get_comment_ids(conn: sqlite3.Connection, claim_id: str, parent_id: str = No curs = conn.execute(""" SELECT comment_id FROM COMMENTS_ON_CLAIMS WHERE claim_id = ? AND parent_id IS NULL LIMIT ? OFFSET ? - """, (claim_id, page_size, page_size * abs(page - 1),) - ) + """, (claim_id, page_size, page_size*abs(page - 1),) + ) else: curs = conn.execute(""" SELECT comment_id FROM COMMENTS_ON_CLAIMS WHERE claim_id = ? AND parent_id = ? LIMIT ? OFFSET ? """, (claim_id, parent_id, page_size, page_size * abs(page - 1),) - ) + ) return [tuple(row)[0] for row in curs.fetchall()] @@ -175,7 +175,7 @@ def get_channel_id_from_comment_id(conn: sqlite3.Connection, comment_id: str): channel = conn.execute(""" SELECT channel_id, channel_name FROM COMMENTS_ON_CLAIMS WHERE comment_id = ? """, (comment_id,) - ).fetchone() + ).fetchone() return dict(channel) if channel else dict() From c38dfe25305e2d9606c3d7c2775b1d6ae51b2867 Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Tue, 30 Jul 2019 01:57:29 -0400 Subject: [PATCH 3/3] Updates readme --- README.md | 45 ++++++++++++++++++++++++++------------------- setup.py | 2 +- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index d762742..23f4269 100644 --- a/README.md +++ b/README.md @@ -4,22 +4,17 @@ This is the code for the LBRY Comment Server. Fork it, run it, set it on fire. Up to you. -## Prerequisites -In order to run the comment server properly, you will need the -following: +## Before Installing + +Comment Deletion requires having the [`lbry-sdk`](https://github.com/lbryio/lbry-sdk) +in order to validate & properly delete comments. + + - 0. A Unix Compliant Operating System (e.g: Ubuntu, RedHat, Hannah Montana, etc.) - 1. Any recent version of Sqlite3 - 2. Python 3.6+ (including `python3-dev`, `python3-virtualenv`, `python3-pip`) - Note: You must specify the specific python version you're using, - e.g. for Python3.6, you would install `python36-dev`. You're smart enough to figure the rest out from here ;) - 3. (Optional) Reverse Proxy software to handle a public-facing API. - We recommend Caddy, though there is an `nginx.conf` file under `config`. - 5. Patience (Strongly recommended but often neglected) ## Installation -Installing the server: +#### Installing the server: ```bash $ git clone https://github.com/osilkin98/comment-server @@ -31,22 +26,34 @@ $ virtualenv --python=python3 venv # Enter the virtual environment $ source venv/bin/activate -# install the library dependencies -(venv) $ pip install -r requirements.txt +# install the Server as a Executable Target +(venv) $ python setup.py develop ``` +### Installing the systemd Service Monitor + +As a super-user, copy the .service and .target files to the systemd directory: +```bash +$ sudo comment-server/config/comment-server* /etc/systemd/system +``` +Then `$ sudo systemctl daemon-reload` to refresh the systemd service files. + + + ## Usage ### Running the Server To start the server, simply run: ```bash -# to enter server's venv -$ source venv/bin/activate - -# To start server as daemon process -(venv) $ python -m main & +$ sudo systemctl start comment-server.target ``` +(Optional) Enable the server to run on booting: +```bash +$ sudo systemctl enable --now comment-server.target +``` + + ### Testing To Test the database, simply run: diff --git a/setup.py b/setup.py index 8f5d57d..f7397f8 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ ROOT = os.path.dirname(__name__) setup( name='CommentServer', - version='0.0.1', + version='0.0.2', packages=find_packages(exclude=('tests',)), entry_points={ 'console_scripts': 'commentserv=src.main:main'