Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Naomi to start automatically #317

Open
aaronchantrill opened this issue Jan 30, 2021 · 6 comments
Open

Getting Naomi to start automatically #317

aaronchantrill opened this issue Jan 30, 2021 · 6 comments
Labels
Hacktoberfest Small or non-core issues that could be worked on by Hacktoberfest participants Priority: Low Status: Available Type: Enhancement

Comments

@aaronchantrill
Copy link
Contributor

Detailed Description

I'd like to be able to have Naomi start automatically when the computer boots up rather than having to connect to a command line and manually start Naomi.

Context

Having Naomi start automatically would be convenient in some cases.

Possible Implementation

Ideally the Naomi service would be started by a systemd script. Unfortunately, there is currently no way to attach a console to a running server, so you would not be able to monitor Naomi (especially the volume level monitor) that way. We need to separate out the client and server and provide api hooks for monitoring Naomi. I know that's on the to-do list.

In the meantime, I like to start Naomi inside "screen" so I can disconnect my laptop without stopping Naomi, and reconnect later, so what I'd like to do is come up with an @reboot cron job that would run Naomi inside screen. Ideally, this would not involve any external scripts - I could just put this line into crontab and have Naomi start up every time I start the computer. Then, if I want to see what Naomi is doing, use the "screen -r" command to reconnect to the session.

@AustinCasteel AustinCasteel added this to New Issues in Core Development Jan 30, 2021
@aaronchantrill aaronchantrill added Hacktoberfest Small or non-core issues that could be worked on by Hacktoberfest participants Priority: Low Type: Enhancement Status: Available labels Sep 20, 2021
@aaronchantrill
Copy link
Contributor Author

I was finally able to get Naomi to start automatically at system boot by creating a NaomiRebootScript.sh script:

export PATH=/usr/local/bin:/usr/bin:/bin
pulseaudio --start
export WORKON_HOME=/home/pi/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/home/pi/.local/bin/virtualenv
source /home/pi/.local/bin/virtualenvwrapper.sh
workon Naomi
python /home/pi/Naomi/Naomi.py "$@"

then running
$ crontab -e
and adding the following line:
@reboot /usr/bin/screen -dm bash -c "/home/pi/Naomi/NaomiRebootScript.sh"

If I want to see what Naomi is doing, then I can ssh into the raspberry pi and use screen -r to restore the screen Naomi is currently running in.

I am going to add a --quiet option to Naomi which will prevent it from asking about any missing parameters (--quiet flag for Naomi #345) and add that flag to the call to the crontab line to prevent Naomi from blocking during startup.

@aaronchantrill
Copy link
Contributor Author

After upgrading to Debian Bullseye and Pipewire, the above stopped working again. I decided to start it as a systemd service this time, so put the following into ~/.config/naomi/Naomi_start.sh:

#!/bin/bash

export XDG_RUNTIME_DIR=/run/user/$(id -u)
export WORKON_HOME=/home/naomi/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=~/.local/bin/virtualenv
source ~/.local/bin/virtualenvwrapper.sh
workon Naomi
python /home/naomi/Naomi/Naomi.py "$@"

and the following (updating the path to the user's home directory) into Naomi/etc/systemd/system/Naomi.service:

[Unit]
Description=Your plastic pal who's fun to be with
After=network.target sound.target

[Service]
Type=forking
User=naomi
ExecStart=/usr/bin/screen -d -m "/home/<user>/.config/naomi/Naomi_start.sh"
RemainAfterExit=true

[Install]
WantedBy=multi-user.target

I would like to add this option to the installer at some point.

@aaronchantrill
Copy link
Contributor Author

I tried using this same setup on Armbian Bullseye, but got the error message "Audio device with slug 'pulse' not found"

I assume this means that the pulseaudio server is not running, so I tried explicitly starting it after setting the XDG_RUNTIME_DIR, but now I am getting the error message:
E: [autospawn] core-util.c: Failed to create secure directory (/run/user/1000/pulse): No such file or directory

It looks like whatever process I need to create the /run/user/1000 directory is not kicking off when SystemD launches the service as my user. I'm looking into why this is now.

@aaronchantrill
Copy link
Contributor Author

If I add a "pulseaudio --check; echo $?", I get:

checking pulseaudio:
E: [pulseaudio] core-util.c: Failed to create secure directory (/run/user/1000/pulse): No such file or directory
1

so instead of the exit code being void (not running) or 0 (running) it is 1 for an error even attempting to run pulseadio. This may be related to the fact that I installed the Mate desktop recently, since pulseaudio is tightly tied to x and I'm not starting any x sessions.

I'm curious if pipewire would have the same issues.

@aaronchantrill
Copy link
Contributor Author

After adding xstart to the NaomiReboot.sh file, I get:

(EE) 
Fatal server error:
(EE) xf86OpenConsole: Cannot open virtual console 1 (Permission denied)
(EE) 
(EE) 
Please consult the The X.Org Foundation support 
         at http://wiki.x.org
 for help. 
(EE) Please also check the log file at "/home/naomi/.local/share/xorg/Xorg.0.log" for additional information.
(EE) 
(EE) Server terminated with error (1). Closing log file.
xinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: server error

@aaronchantrill
Copy link
Contributor Author

I'm starting to suspect that there is something wrong with the Armbian X86 setup. @AustinCasteel had mentioned a while ago that he was not able to get either xrdp or VNC working in Armbian, and I think that may because of this same issue. I'm going to try upgrading to Armbian Bookworm and also switching from pulseaudio to pipewire and see if I still have these same issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest Small or non-core issues that could be worked on by Hacktoberfest participants Priority: Low Status: Available Type: Enhancement
Projects
Development

No branches or pull requests

1 participant