mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-28 17:54:15 +01:00
support different users for autostart
This commit is contained in:
parent
0ec02447d5
commit
4721cf3a8c
4 changed files with 29 additions and 15 deletions
18
cbpi/cli.py
18
cbpi/cli.py
|
@ -150,12 +150,27 @@ class CraftBeerPiCli():
|
||||||
else:
|
else:
|
||||||
print("CraftBeerPi Autostart is {}OFF{}".format(Fore.RED,Style.RESET_ALL))
|
print("CraftBeerPi Autostart is {}OFF{}".format(Fore.RED,Style.RESET_ALL))
|
||||||
elif(name == "on"):
|
elif(name == "on"):
|
||||||
|
user=os.getlogin()
|
||||||
print("Add craftbeerpi.service to systemd")
|
print("Add craftbeerpi.service to systemd")
|
||||||
try:
|
try:
|
||||||
if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is False:
|
if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is False:
|
||||||
|
templatefile=self.config.get_file_path("craftbeerpi.template")
|
||||||
|
shutil.os.system('cp "{}" "{}"'.format(templatefile,self.config.get_file_path("craftbeerpi.service")))
|
||||||
srcfile = self.config.get_file_path("craftbeerpi.service")
|
srcfile = self.config.get_file_path("craftbeerpi.service")
|
||||||
|
import jinja2
|
||||||
|
|
||||||
|
templateLoader = jinja2.FileSystemLoader(searchpath=os.path.join(self.config.get_file_path("")))
|
||||||
|
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||||
|
operatingsystem = str(platform.system()).lower()
|
||||||
|
if operatingsystem.startswith("win"):
|
||||||
|
srcfile=str(srcfile).replace('\\','/')
|
||||||
|
|
||||||
|
template = templateEnv.get_template("craftbeerpi.service")
|
||||||
|
outputText = template.render(user=user)
|
||||||
|
with open(srcfile, "w") as fh:
|
||||||
|
fh.write(outputText)
|
||||||
destfile = os.path.join("/etc/systemd/system")
|
destfile = os.path.join("/etc/systemd/system")
|
||||||
shutil.os.system('sudo cp "{}" "{}"'.format(srcfile,destfile))
|
shutil.os.system('sudo mv "{}" "{}"'.format(srcfile,destfile))
|
||||||
print("Copied craftbeerpi.service to /etc/systemd/system")
|
print("Copied craftbeerpi.service to /etc/systemd/system")
|
||||||
shutil.os.system('sudo systemctl enable craftbeerpi.service')
|
shutil.os.system('sudo systemctl enable craftbeerpi.service')
|
||||||
print('Enabled craftbeerpi service')
|
print('Enabled craftbeerpi service')
|
||||||
|
@ -188,7 +203,6 @@ class CraftBeerPiCli():
|
||||||
print(e)
|
print(e)
|
||||||
return
|
return
|
||||||
return
|
return
|
||||||
|
|
||||||
def chromium(self, name):
|
def chromium(self, name):
|
||||||
'''Enable or disable autostart'''
|
'''Enable or disable autostart'''
|
||||||
if(name == "status"):
|
if(name == "status"):
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=Craftbeer Pi
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
WorkingDirectory=/home/pi
|
|
||||||
ExecStart=/home/pi/.local/bin/cbpi start
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
9
cbpi/config/craftbeerpi.template
Normal file
9
cbpi/config/craftbeerpi.template
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Craftbeer Pi
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
WorkingDirectory=/home/{{ user }}
|
||||||
|
ExecStart=/home/{{ user }}/.local/bin/cbpi start
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -94,7 +94,7 @@ class ConfigFolder:
|
||||||
#['fermenter_data.json', 'file'], created by fermentation_controller @ start if not available
|
#['fermenter_data.json', 'file'], created by fermentation_controller @ start if not available
|
||||||
#['step_data.json', 'file'], created by step_controller @ start if not available
|
#['step_data.json', 'file'], created by step_controller @ start if not available
|
||||||
['config.json', 'file'],
|
['config.json', 'file'],
|
||||||
['craftbeerpi.service', 'file'],
|
['craftbeerpi.template', 'file'],
|
||||||
['chromium.desktop', 'file'],
|
['chromium.desktop', 'file'],
|
||||||
['dashboard', 'folder'],
|
['dashboard', 'folder'],
|
||||||
['dashboard/widgets', 'folder'],
|
['dashboard/widgets', 'folder'],
|
||||||
|
@ -181,7 +181,7 @@ class ConfigFolder:
|
||||||
self.copyDefaultFileIfNotExists("fermenter_data.json")
|
self.copyDefaultFileIfNotExists("fermenter_data.json")
|
||||||
self.copyDefaultFileIfNotExists("step_data.json")
|
self.copyDefaultFileIfNotExists("step_data.json")
|
||||||
self.copyDefaultFileIfNotExists("config.json")
|
self.copyDefaultFileIfNotExists("config.json")
|
||||||
self.copyDefaultFileIfNotExists("craftbeerpi.service")
|
self.copyDefaultFileIfNotExists("craftbeerpi.template")
|
||||||
self.copyDefaultFileIfNotExists("chromium.desktop")
|
self.copyDefaultFileIfNotExists("chromium.desktop")
|
||||||
|
|
||||||
print("Config Folder created")
|
print("Config Folder created")
|
||||||
|
@ -206,5 +206,5 @@ class ConfigFolder:
|
||||||
shutil.chown(os.path.join(dirpath, filename), owner, group)
|
shutil.chown(os.path.join(dirpath, filename), owner, group)
|
||||||
except:
|
except:
|
||||||
print("problems assigning file or folder permissions")
|
print("problems assigning file or folder permissions")
|
||||||
print("if this happend on windows its fine")
|
print("if this happened on windows its fine")
|
||||||
print("if this happend in the dev container running inside windows its also fine but you might have to rebuild the container if you run into further problems")
|
print("if this happened in the dev container running inside windows its also fine but you might have to rebuild the container if you run into further problems")
|
||||||
|
|
Loading…
Reference in a new issue