PiBrewing / craftbeerpi4

GNU General Public License v3.0
58 stars 28 forks source link

Unable to Configure Autostart #142

Closed stamandster closed 3 months ago

stamandster commented 4 months ago

As you can see from the output below, there is also not a craftbeerpi.service file in my ./config (though there is a .template file), any direction would be appreciated. I did attempt to follow the direction here https://openbrewing.gitbook.io/craftbeerpi4_support/readme/server-installation

chris@brewpi:~ $ cbpi autostart on

Welcome to CBPi 4.4.0

config folder path : ./config logs folder path : /home/chris/logs


Debug-log-level is 30


Traceback (most recent call last): File "/home/chris/.local/bin/cbpi", line 8, in sys.exit(main()) ^^^^^^ File "/home/chris/.local/pipx/venvs/cbpi4/lib/python3.11/site-packages/click/core.py", line 1157, in call return self.main(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/.local/pipx/venvs/cbpi4/lib/python3.11/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "/home/chris/.local/pipx/venvs/cbpi4/lib/python3.11/site-packages/click/core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/.local/pipx/venvs/cbpi4/lib/python3.11/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/.local/pipx/venvs/cbpi4/lib/python3.11/site-packages/click/core.py", line 783, in invoke return __callback(args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/.local/pipx/venvs/cbpi4/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func return f(get_current_context(), args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/chris/.local/pipx/venvs/cbpi4/lib/python3.11/site-packages/cbpi/cli.py", line 348, in autostart context.obj.autostart(name) File "/home/chris/.local/pipx/venvs/cbpi4/lib/python3.11/site-packages/cbpi/cli.py", line 168, in autostart user=os.getlogin() ^^^^^^^^^^^^^ OSError: [Errno 6] No such device or address

avollkopf commented 4 months ago

the craftbeerpi.service file is not required as it is being generated from the craftbeerpi.template file. In the past, there used to be a craftbeerpi.service file. However, in this case usesers were only able to run cbpi under user pi. with the template file, you are also able to run cbpi un your case under user chris. From this log I cannot conclude what's really the issue. Did you run cbpi setup from the same path?

stamandster commented 3 months ago

Hi @avollkopf sorry for the delay. I'm able to start the server just fine using "cbpi start", and I attempted "cbpi autostart on" and I ran "cbpi setup" from the same locations, /home/chris. This is what I have in my craftbeerbi.template

[Unit] Description=Craftbeer Pi

[Service] WorkingDirectory=/home/chris ExecStart={{ path }} start

[Install] WantedBy=multi-user.target

I was able to solve through testing python script to see if it would do it for me directly and it also failed on using os.getlogin()

import os; print (os.getlogin())

However, through some googling, the following did work for me

import pwd, os; print (pwd.getpwuid(os.getuid()).pw_name)

I edited my cli.py to use that for user query instead of os.getlogin() and was successful in created the service and cbpi is running

chris@brewpi:~ $ cbpi autostart on

Welcome to CBPi 4.4.0

config folder path : ./config logs folder path : /home/chris/logs


Debug-log-level is 30


Add craftbeerpi.service to systemd Copied craftbeerpi.service to /etc/systemd/system Created symlink /etc/systemd/system/multi-user.target.wants/craftbeerpi.service → /etc/systemd/system/craftbeerpi.service. Enabled craftbeerpi service Started craftbeerpi.service

Also the documentation at -- https://openbrewing.gitbook.io/craftbeerpi4_support/readme/server-installation It says "craftbeerpi.service" instead of "craftbeerpi.template" to edit.

avollkopf commented 3 months ago

Thanks for the response. I will look into it and might adapt the code accordingly

stamandster commented 3 months ago

Here's some reason why I used this snippet instead of os.getlogin(), I am also logged in remotely. So I have a feeling this is why it wasn't working. If I had do it directly on the RPi it might have worked. But in my situation, it's in the basement headless.

https://stackoverflow.com/questions/47444178/difference-between-os-getlogin-and-os-environ-for-getting-username https://github.com/parmentelat/apssh/issues/1

avollkopf commented 3 months ago

fixed with https://github.com/PiBrewing/craftbeerpi4/commit/62370980e0b052a9d126d7e753a0dbe9282bdafd