mirror of
https://github.com/mynodebtc/mynode.git
synced 2024-11-13 17:09:15 +00:00
Create user when initializing application
This commit is contained in:
parent
a75baf9b2d
commit
825409f883
|
@ -596,7 +596,7 @@ def clear_custom_app_version(short_name):
|
||||||
## Single Application Actions
|
## Single Application Actions
|
||||||
######################################################################################
|
######################################################################################
|
||||||
def create_application_user(app_data):
|
def create_application_user(app_data):
|
||||||
log_message(" Running create_application_user...")
|
#log_message(" Running create_application_user...")
|
||||||
username = app_data["linux_user"]
|
username = app_data["linux_user"]
|
||||||
if not linux_user_exists(username):
|
if not linux_user_exists(username):
|
||||||
linux_create_user(username)
|
linux_create_user(username)
|
||||||
|
@ -605,8 +605,8 @@ def create_application_user(app_data):
|
||||||
add_user_to_group(username, "bitcoin")
|
add_user_to_group(username, "bitcoin")
|
||||||
|
|
||||||
# If docker app, add them to docker
|
# If docker app, add them to docker
|
||||||
#if app_data["requires_docker_image_installation"]:
|
if app_data["requires_docker_image_installation"]:
|
||||||
# add_user_to_group(username, "docker")
|
add_user_to_group(username, "docker")
|
||||||
|
|
||||||
def create_application_folders(app_data):
|
def create_application_folders(app_data):
|
||||||
log_message(" Running create_application_folders...")
|
log_message(" Running create_application_folders...")
|
||||||
|
@ -769,6 +769,8 @@ def init_dynamic_app(app_info):
|
||||||
app_name = app_info["short_name"]
|
app_name = app_info["short_name"]
|
||||||
app_dir = DYNAMIC_APPLICATIONS_FOLDER + "/" + app_name
|
app_dir = DYNAMIC_APPLICATIONS_FOLDER + "/" + app_name
|
||||||
log_message(" Loading " + app_name + "...")
|
log_message(" Loading " + app_name + "...")
|
||||||
|
# Create user if necessary
|
||||||
|
create_application_user(app_info)
|
||||||
# Install Service File (if exists)
|
# Install Service File (if exists)
|
||||||
if (os.path.isfile(app_dir+"/"+app_name+".service")):
|
if (os.path.isfile(app_dir+"/"+app_name+".service")):
|
||||||
os.system("cp -f {} {}".format(app_dir+"/"+app_name+".service", "/etc/systemd/system/"+app_name+".service"))
|
os.system("cp -f {} {}".format(app_dir+"/"+app_name+".service", "/etc/systemd/system/"+app_name+".service"))
|
||||||
|
|
|
@ -8,6 +8,7 @@ import codecs
|
||||||
import urllib
|
import urllib
|
||||||
import requests
|
import requests
|
||||||
import pwd
|
import pwd
|
||||||
|
import grp
|
||||||
|
|
||||||
mynode_logger = None
|
mynode_logger = None
|
||||||
|
|
||||||
|
@ -372,5 +373,16 @@ def linux_create_user(username, make_home_folder=False):
|
||||||
cmd = "useradd {} -s /bin/bash {} || true".format(dash_m, username)
|
cmd = "useradd {} -s /bin/bash {} || true".format(dash_m, username)
|
||||||
run_linux_cmd(cmd, print_command=True)
|
run_linux_cmd(cmd, print_command=True)
|
||||||
|
|
||||||
|
def user_is_in_group(username, group):
|
||||||
|
try:
|
||||||
|
group_info = grp.getgrnam(group)
|
||||||
|
for grpusr in group_info.gr_mem:
|
||||||
|
if username == grpusr:
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
return False
|
||||||
|
|
||||||
def add_user_to_group(username, group):
|
def add_user_to_group(username, group):
|
||||||
run_linux_cmd("adduser {} {}".format(username, group), print_command=True)
|
if not user_is_in_group(username, group):
|
||||||
|
run_linux_cmd("adduser {} {}".format(username, group), print_command=True)
|
Loading…
Reference in New Issue
Block a user