add manage command: install
This commit is contained in:
parent
af5c968d7e
commit
9cf61e5895
|
@ -1,9 +1,11 @@
|
|||
import json, sys
|
||||
import json, os, sys
|
||||
|
||||
from configparser import ConfigParser
|
||||
from datetime import datetime
|
||||
from envbash import load_envbash
|
||||
from getpass import getuser
|
||||
from izzylib import DotDict, Path, boolean, logging, prompt
|
||||
from grp import getgrgid
|
||||
from izzylib import DotDict, Path, boolean, logging, prompt, sudo
|
||||
from izzylib.sql import Database
|
||||
from os import environ as env
|
||||
from urllib.parse import urlparse
|
||||
|
@ -51,6 +53,13 @@ class Command:
|
|||
python3 -m uncia.manage help:
|
||||
Show this message.
|
||||
|
||||
python3 -m uncia.manage setup:
|
||||
A series of questions will be asked to generate the env file.
|
||||
|
||||
python3 -m uncia.manage install [systemd or sysv]:
|
||||
Generate an init service config and put it in the right location. Uses
|
||||
"systemd" by default, but "sysv" can be specified instead
|
||||
|
||||
python3 -m uncia.manage list:
|
||||
List currently subscribed instances.
|
||||
|
||||
|
@ -61,14 +70,14 @@ python3 -m remove <actor, inbox, or domain>:
|
|||
Remove an instance and any retries associated with it from the database.
|
||||
|
||||
python3 -m uncia.manage ban <handle@domain or domain> [*reason]:
|
||||
Ban a user or domain. A reason may optionally be specified.
|
||||
Ban a user or domain. A reason may optionally be specified. Quotes not necessary for reason.
|
||||
|
||||
python3 -m uncia.manage unban <handle@domain or domain>: **
|
||||
Unban a user or domain
|
||||
|
||||
python3 -m uncia.manage bans ["users" or "domains"]:
|
||||
List the currently banned domains and users. A ban type ("users"/"domains")
|
||||
may be specified to only list that type.
|
||||
List the currently banned domains and users. A ban type ("users"/"domains")
|
||||
may be specified to only list that type.
|
||||
|
||||
python3 -m uncia.manage rules [list]:
|
||||
List the current rules.
|
||||
|
@ -109,10 +118,64 @@ python3 -m uncia.manage convert [pleroma or uncia]:
|
|||
Pleroma Relay by default.
|
||||
|
||||
* = The relay needs to be running for the command to work
|
||||
** = Caching prevents this from taking effect until restart.
|
||||
** = Caching prevents this from taking effect until restart
|
||||
'''
|
||||
|
||||
|
||||
def cmd_setup(self):
|
||||
pass
|
||||
|
||||
|
||||
def cmd_install(self, init='systemd'):
|
||||
if init == 'systemd':
|
||||
srvfile = path.config.join('uncia.service')
|
||||
|
||||
initcfg = ConfigParser()
|
||||
initcfg['Unit'] = {
|
||||
'Description': 'Uncia Relay',
|
||||
'After': 'network.target'
|
||||
}
|
||||
|
||||
initcfg['Service'] = {
|
||||
'User': getuser(),
|
||||
'Group': getgrgid(os.getgid()),
|
||||
'WorkingDirectory': Path.cwd,
|
||||
'ExecStart': f'{sys.executable} -m uncia',
|
||||
'Restart': 'always',
|
||||
'StartLimitIntervalSec': 30,
|
||||
'StartLimitBurst': 5
|
||||
}
|
||||
|
||||
initcfg['Install'] = {
|
||||
'WantedBy': 'multi-user.target'
|
||||
}
|
||||
|
||||
with srvfile.open('w') as fd:
|
||||
initcfg.write(fd)
|
||||
|
||||
elif init == 'sysv':
|
||||
return '¯\_(ツ)_/¯'
|
||||
|
||||
else:
|
||||
return f'Error: Invalid service type: {init}\nValid types: systemd, sysv'
|
||||
|
||||
return f'Service file saved to {path.config.join("uncia.service")}'
|
||||
|
||||
# incomplete code to copy service file
|
||||
#copy_srv = None
|
||||
|
||||
#while type(copy_srv) != bool:
|
||||
#if copy_srv != None:
|
||||
#print('Please specify a boolean (yes/no, y/n, true/false, etc)')
|
||||
|
||||
#copy_srv = prompt('Copy service file to /etc/systemd/system/uncia.service?',
|
||||
#valtype = lambda x: boolean(x, return_value=True),
|
||||
#default = True
|
||||
#)
|
||||
|
||||
|
||||
|
||||
|
||||
def cmd_config(self, key=None, value=None):
|
||||
with db.session as s:
|
||||
if key and value:
|
||||
|
|
|
@ -74,9 +74,9 @@ async def AuthCheck(request):
|
|||
raise error.Forbidden('no')
|
||||
|
||||
if request.path in ['/inbox', '/actor'] and request.method.lower() == 'post':
|
||||
## The actor was deleted, so return a 202 to not get the same message over and over again
|
||||
if request.actor == False:
|
||||
raise error.Accepted({'error': 'Could not fetch deleted actor'})
|
||||
## The actor was deleted, so return a 200 to not get the same message over and over again
|
||||
if request.signature and request.actor == False:
|
||||
raise error.Ok({'error': 'Could not fetch deleted actor'})
|
||||
|
||||
if not request.actor:
|
||||
raise error.Unauthorized({'error': 'Could not get actor'})
|
||||
|
|
Loading…
Reference in a new issue