Create user when initializing application

This commit is contained in:
Taylor Helsper 2023-01-03 18:44:00 -06:00
parent a75baf9b2d
commit 825409f883
2 changed files with 18 additions and 4 deletions

View File

@ -596,7 +596,7 @@ def clear_custom_app_version(short_name):
## Single Application Actions
######################################################################################
def create_application_user(app_data):
log_message(" Running create_application_user...")
#log_message(" Running create_application_user...")
username = app_data["linux_user"]
if not linux_user_exists(username):
linux_create_user(username)
@ -605,8 +605,8 @@ def create_application_user(app_data):
add_user_to_group(username, "bitcoin")
# If docker app, add them to docker
#if app_data["requires_docker_image_installation"]:
# add_user_to_group(username, "docker")
if app_data["requires_docker_image_installation"]:
add_user_to_group(username, "docker")
def create_application_folders(app_data):
log_message(" Running create_application_folders...")
@ -769,6 +769,8 @@ def init_dynamic_app(app_info):
app_name = app_info["short_name"]
app_dir = DYNAMIC_APPLICATIONS_FOLDER + "/" + app_name
log_message(" Loading " + app_name + "...")
# Create user if necessary
create_application_user(app_info)
# Install Service File (if exists)
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"))

View File

@ -8,6 +8,7 @@ import codecs
import urllib
import requests
import pwd
import grp
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)
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):
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)