Fresh install: several issues. (Touchpad behaves strangely, performance issues)

main.go doesn't run without sudo, and it still isn't kept after a restart :frowning: I am able to run the main.go file from anywhere, but I have to manually set the changed path every time I boot up the computer. It doesn't stay after reboot.

Okay, but if the binary installed alright and works that is progress.

Once it is installed, can you move the binary and see if it still runs?

sudo mv ~/*whatever_the_path_is_now*/main.go /usr/local/bin/

oh, I already moved it, I moved it to /usr/local/bin/touchpad to be neat. I made a touchpad folder to keep it organized, so the binary is in /usr/local/bin/touchpad/main.go. It runs just fine, but it still has the issue of not running on startup. :frowning:

Okay thatā€™s great!

Letā€™s crack open the systemd service:

micro /etc/systemd/system/driver.service

Go down to the ExecStart line, and change it to point to the binary.

ExecStart=/usr/local/bin/touchpad/main.go

Save and exit, then reload the daemon and restart the service.

sudo systemctl daemon-reload
sudo systemctl restart driver.service

Reboot and test. :crossed_fingers:

EDIT

Iā€™m not sure, but the extra directory inside of /usr/local/bin might not work unless it is explicitly added to the PATH. So if the service doesnā€™t work, I would try either adding /usr/local/bin/touchpad to the PATH, or scrap the extra directory and place the binary directly in /usr/local/bin.

1 Like

Still nothing, tried both in /usr/local/bin/touchpad and directly into /usr/local/bin. systemctl status still gives me "Permissions denied" like before.

Hmm, perhaps systemd is unhappy with the permissions of the binary. Try giving root ownership and see if it helps.

sudo chown root:root /usr/local/bin/main.go
sudo chmod 744 /usr/local/bin/main.go

Progress, finally... I'm left with one last error:

Oct 25 10:57:26 nona-dynabookportegex50g touchpad.sh[770]: usr/local/bin/main.go:11:2: no required module provides package github.com/go-vgo/robotgo: go.mod file not found in current directory or any parent directory; see 'go help module>

The go.mod file is found in my directory. I've tried go get github.com/go-vgo/robotgo in the terminal to see if it can get the files. Oddly enough, it works when I run it via sudo sh or sudo go run.

Er, no, thatā€™s the source. Binary will be an executable file without extension.
Was that a typo or is it still running from the .go source and not the binary?
If so, I think itā€™s a likely source of problems, also because permissions.

Iā€™m not too familiar with Go, but seeing it likes to keep all its stuff in a user directory, it makes sense that modules downloaded as the normal user are unknown when running as superuser, and that go run will need sudo in order to be able to do anything in a system directory where the normal user has no write permissions.

Iā€™d try my best to avoid all that though.
Compile it once as normal user as advised above, then move the resulting binary where appropriate and set owner/permissions.

Since itā€™s a single file, it should be OK to just give it a name unlikely to clash with anything else and throw it in /usr/bin/, but anywhere else is fine, provided that either 1) the program is called with the full absolute path or 2) the directory where the program resides is in the PATH.

edit: the binary is mmm, in the same folder as the sources (after compiling).

sudo chown root:root mmm
sudo mv mmm /usr/bin/fix-my-trackpad

Then remember to update the service / cron job / script / whatever it is to run the program, from sudo go run ... to fix-my-trackpad (or sudo fix-my-trackpad in case it needs root to function).

2 Likes

sry but I'm confused.... I have to compile it? I can run it by either using go run, or sudo sh, and to make it easier, I stuck with making the program into a .sh file. I already have root permissions, the error I get now is that I'm lacking the module, which is strange because I can run it from the terminal just fine, and the modules should be there in the directory. Unless there's something else I have to try?

Every time you run it with go run, the program does a quick compilation and build (and then runs it). There are too many moving parts/complicating factors to make this process work easily as a service or startup task.

If you install it instead, with go install, then it will create a binary that is already compiled and built, and can exist independently from all the other build stuff in your /home directory. That will be the binary you can set up into your startup service.

@meanruse is right--after you install and have a proper binary, it shouldn't have a .go extension. That is, instead of foo.go it should just be foo.

After you get the binary properly installed, you shouldn't need any extra scripts or anything--it should run just like any other program.

So instead of writing go run /usr/local/bin/main.go, it should be go install /usr/local/bin/main.go? Apologies, I'm a bit lost here.... and writing go install keeps the .go extension of it.

I think it's simply go install from the sources directory (where main.go is).
Then the binary should be in $GOPATH/mmm.
It's also OK to leave it there and call it with the absolute path.
See go help install for details.

I agree, this is also the impression I get. Run go install and it will make a new standalone binary and stick it into the GOBIN if there is one, or whatever the default path if not.

go install wonā€™t change the foo.go file, or any other file for that matterā€“it should make a new file, which will be the binary you are looking for. Poke around in the GOPATH and find it!

I run go install over and over, it stops for a bit and then finishes the task. My gopath is /home/nona/go, but I don't see anything.... Just two folders called bin and pkg. Am I supposed to be looking for a file named main, no .go extension?

What is inside the bin folder?

Even easier: go build and there should be mmm along main.go.
That's the binary.

building the binary gives me go build main.go: build output "main.go" already exists and is not an object file

image

I think that's it!

What happens if you try to run it?

/home/nona/go/bin/main

no packages loaded from /usr/local/bin/go/bin/main is what I get when trying to run...

Uh ohā€¦that does not look right. What is the output of go env?