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

Request/Question: Linux service #144

Closed
Aetherinox opened this issue Oct 24, 2023 · 8 comments · Fixed by #145
Closed

Request/Question: Linux service #144

Aetherinox opened this issue Oct 24, 2023 · 8 comments · Fixed by #145

Comments

@Aetherinox
Copy link

Aetherinox commented Oct 24, 2023

I have numerous users who utilize my own repository, one asked for an easier way to install opengist (personally, it's easy enough, but you know, there's always one).

I looked through the docs and came across the mentioning of defining the home directory by prefixing

Usage via command line :

OG_LOG_LEVEL=info ./opengist

However, I attempted to do that via a service by utilizing

ExecStart=OG_OPENGIST_HOME=/home/testuser/ ./opengist --config=/etc/opengist/config.yml

Which doesn't seem to get recognized, as I get the following error below:

Oct 24 14:57:34 athx-01 systemd[1]: Started opengist.service - Opengist Daemon.
Oct 24 14:57:34 athx-01 opengist[28728]: Opengist v1.5.2
Oct 24 14:57:34 athx-01 opengist[28728]: panic: $HOME is not defined
Oct 24 14:57:34 athx-01 opengist[28728]: goroutine 1 [running]:

Am I using the wrong syntax for this?
I was able to package up Opengist and implement a opengist.desktop, but the user has to right click and select "Allow Launch", but I can promise there's going to be someone out there completely oblivious to that fact.

And it's actually puzzling, because even if I manually add a path to /etc/opengist/config.yml:

opengist-home: /home/aetherinox/

It still seems to throw the error. So I'm not sure what my options are. Would just be a benefit.
Right now with the .deb, the opengist bin gets installed to /usr/bin/opengist so all they have to do is just edit the config and away they go, but being able to attach it to a service would be a bonus.


Also, if you ever plan to create a .deb for whatever reason, I added the licensing, all your contributors and made a man page for it, so you're welcome to it. Man pages are a pain.

It's all in /usr/share/man and /usr/share/doc

aaAZKoL

@alexlehm
Copy link

maybe try to set the variables in a small shell script like
export HOME=/home/yourname
cd $HOME
./opengist --config=/etc/opengist/config.yml

then its easy to add other variables if necessary

@Aetherinox
Copy link
Author

Aetherinox commented Oct 25, 2023

That's the weirder part, $HOME is already defined prior to attempting to run the service, it's just not capturing it. So I'm not sure where it's looking. I've pulled through the source code for opengist, but I can't seem to find a reason. Think it has something to do with Go in particular.

And I've tried running systemctl without sudo to ensure it uses the correct user home dir.

However, if I edit the service and use one of the two options

Option 1

[Service]
Type=simple
User=%u

Option 2

[Service]
Environment=HOME=/home/%u

It then works fine.

● opengist.service - Opengist Daemon
     Loaded: loaded (/etc/systemd/system/opengist.service; disabled; preset: enabled)
     Active: active (running) since Wed 2023-10-25 08:30:52 MST; 2s ago
   Main PID: 5485 (opengist)
      Tasks: 6 (limit: 4600)
     Memory: 16.4M
        CPU: 369ms
     CGroup: /system.slice/opengist.service
             └─5485 opengist --config=/etc/opengist/config.yml

Oct 25 08:30:52 athx-01 systemd[1]: Started opengist.service - Opengist Daemon.
Oct 25 08:30:52 athx-01 opengist[5485]: Opengist v1.5.2
Oct 25 08:30:52 athx-01 opengist[5485]: Using YAML config file: /etc/opengist/config.yml
Oct 25 08:30:52 athx-01 opengist[5485]: No environment variables config specified.

Or attempting to run as

systemctl --user start

But I've seen very few users utilize that method.

@Aetherinox
Copy link
Author

Aetherinox commented Oct 25, 2023

Well, unless the developer has some other method, I created an postinst script for a deb package. Everything runs out of box after the .deb is installed and the service works.

Only downside is obviously since it needs a home directory path, the service needs to be executed via a user instead of system. Once the deb is installed, opengist service starts right away, but to stop / check status, they'll have to utilize

systemctl status --user opengist
systemctl stop --user opengist

But it works

ntwwBAI

And with minimal effort from the user.

And then there's the dumbed down way with the installed desktop shortcut

cFoav92

@Aetherinox
Copy link
Author

Just an addition in case anyone finds this ticket. I feel dumb. The developer also provided quick instructions via the docs.

Would have been easier to find, but luckily I pretty much set the systemd service up exactly like this minus the ease of having the doc to reference. I went back today to find a few vars and noticed the systemd file.

@thomiceli
Copy link
Owner

The panic: $HOME is not defined is a valid concern still.

@Aetherinox
Copy link
Author

Aetherinox commented Oct 28, 2023

The panic: $HOME is not defined is a valid concern still.

Can you confirm if this is a Go standard error? Or specific to Opengist? I looked through the Opengist code and I couldn't find any matching strings.

And what are the repercussions of this $home not being defined? I ended up going with the same method you utilized in your doc to create an opengist user and setting the home to /var/lib/opengist. Because when you're dealing with debian packages, there's almost no correct way to call the current user since everything is done in root. So the new user just seemed way easier and better practice instead of writing some hacky code or even worse, using root.

When I start the opengist.service, it seems to create the DB in the correct directory.

Only after I went through the pain of testing all this did I find the docs you provided even though I swear I originally looked a first time, it was just buried. I ended up even picking the same paths that you did.

I also went through this morning and created the arm64 package and tested that out and it seems to work out of box with the correct directories and users since the debian postinst takes care of all of that.

@jolheiser
Copy link
Contributor

jolheiser commented Oct 28, 2023

This is indeed a stdlib error coming from os.UserHomeDir

There are a few solutions, one could be to fall back to . if home isn't defined, or a required flag/config.

The error happens above the config parsing at

homeDir, err := os.UserHomeDir()
, so the error could be held and just use regular validation to check the home dir after all the parsing is done, perhaps.

Depending on how "severe" of an error you consider it to be ("it" being having no HOME env var), you could forego this part

c.OpengistHome = filepath.Join(homeDir, ".opengist")
if homeDir is empty, then further down in checks you could validate and ensure that there is a value.

@Aetherinox
Copy link
Author

Would creating a flag for Opengist be the easiest way? It's more of a "are you up for adding this" question. Because creating a .deb every time you release a new version isn't a big deal, but having a script which starts auto injecting changes and then building on the user's end may start getting a tad bit complicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants