add start stop joplin client terminal

This commit is contained in:
2022-08-30 20:49:50 -04:00
parent 1f73faa7e4
commit ff3011de69
12 changed files with 1576 additions and 27 deletions
+39
View File
@@ -0,0 +1,39 @@
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.9-alpine as compile-image
# Install pip requirements
COPY requirements.txt .
RUN apk add --virtual .build-deps gcc libffi-dev musl-dev
RUN pip install --user -r requirements.txt
FROM python:3.9-alpine
# add nginx
EXPOSE 80
RUN apk add --no-cache nginx
RUN adduser -D -g 'www' www
RUN mkdir /www
RUN chown -R www:www /var/lib/nginx
RUN chown -R www:www /www
RUN mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig
COPY settings/nginx.conf /etc/nginx/nginx.conf
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
COPY --from=compile-image /root/.local /root/.local
ENV PATH=/root/.local/bin:$PATH
WORKDIR /app
COPY . /app
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
#RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
#USER appuser
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
RUN chmod +x /app/runserver.sh
CMD ["/bin/sh", "/app/runserver.sh"]
+74 -23
View File
@@ -6,6 +6,7 @@
# joplin_utils : procedure related joplin application
#
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
import os
import net
import times
import osproc
@@ -15,8 +16,11 @@ import httpcore
import strutils
import strformat
import std/options
import std/httpclient
import std/asyncdispatch
from os import sleep
import std/[asyncdispatch, httpclient]
from posix import read, write, fdatasync, close
# --==--==--==--==--==--==--==--==--==--==-- #
# TYPE : Setup joplin_ping data
@@ -56,6 +60,15 @@ type
latitude*, longitude*, altitude*, order*:seq[float]
req*: Request
# --==--==--==--==--==--==--==--==--==--==-- #
# TYPE : Setup process data structure
# --==--==--==--==--==--==--==--==--==--==-- #
type
program* = object
pid*: int
stdout*: string
stderr*: string
# --==--==--==--==--==--==--==--==--==--==-- #
# DURATION : duration variables
# --==--==--==--==--==--==--==--==--==--==-- #
@@ -281,20 +294,35 @@ proc get_joplin_cli_token*(): string =
return flagValue
# --==--==--==--==--==--==--==--==--==--==-- #
# PROC : launch any program and get PID
# --==--==--==--==--==--==--==--==--==--==-- #
proc launchProgram(app:string = "", workingPath:string = "", arguments:array[2, string]):int {.thread.} =
var p = startProcess(joinPath(workingPath,app), workingPath, arguments)
let pid = p.processID()
var outhdl = outputHandle(p)
var inputhdl = inputHandle(p)
var errhdl = errorHandle(p)
return pid
# --==--==--==--==--==--==--==--==--==--==-- #
# PROC : start Joplin Terminal
# PROC : Start joplin cli
# --==--==--==--==--==--==--==--==--==--==-- #
proc joplin_cli_start*(): bool =
var rc = false
var result = execCmdEx("joplin server start &")
proc joplin_cli_start*():int {.thread.} =
let joplinProcessId = launchProgram("joplin","/usr/bin/",["server","start"])
return joplinProcessId
# --==--==--==--==--==--==--==--==--==--==-- #
# PROC : stop Joplin Terminal
# --==--==--==--==--==--==--==--==--==--==-- #
proc joplin_cli_stop*():int {.thread.} =
let joplinProcessId = launchProgram("joplin","/usr/bin/",["server","stop"])
return joplinProcessId
if result.exitCode == 0:
# echo result.output
rc = true
else:
rc = false
return rc
# --==--==--==--==--==--==--==--==--==--==-- #
@@ -305,26 +333,49 @@ proc joplin_cli_status*(): bool =
var result = execCmdEx("joplin server status")
if result.exitCode == 0:
# echo result.output
rc = true
if "Server is not running" in result.output :
echo "Joplin Terminal cli status is down : ", result.output
rc = false
else:
echo "Joplin Terminal cli status is up : ", result.output
rc = true
else:
rc = false
echo "Error validate joplin terminal status : ", result.output
return rc
# --==--==--==--==--==--==--==--==--==--==-- #
# PROC : start Joplin Terminal
# --==--==--==--==--==--==--==--==--==--==-- #
# proc joplin_cli_start*(): bool =
# var rc = false
# startProcess("joplin","/usr/bin", @["server", "start"])
# #var result = execCmdEx("ls -l /usr/bin/joplin")
# if joplin_cli_status() == true:
# echo "Joplin Terminal started successfully : ",result.output
# rc = true
# else:
# echo "Joplin Terminal didn't start : ",result.output
# rc = false
# return rc
# --==--==--==--==--==--==--==--==--==--==-- #
# PROC : stop Joplin Terminal
# --==--==--==--==--==--==--==--==--==--==-- #
proc joplin_cli_stop*(): bool =
var rc = false
var result = execCmdEx("joplin server stop")
# proc joplin_cli_stop*(): bool =
# var rc = false
# var result = execCmdEx("joplin server stop")
if result.exitCode == 0:
# echo result.output
rc = true
else:
rc = false
return rc
# if result.exitCode == 0:
# # echo result.output
# rc = true
# else:
# rc = false
# return rc
# --==--==--==--==--==--==--==--==--==--==-- #