Problem initializing the uos library in the service

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
32 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Problem initializing the uos library in the service

fredvs
Administrator
Hum, even better if you could give here a simple demo of your service, in attachment as zip file, for example with a simple synth wave.
So I can try it on my system and see what is the problem.
;-)
Reply | Threaded
Open this post in threaded view
|

Re: Problem initializing the uos library in the service

Andrey
In reply to this post by fredvs
All right, Fred. If there is an opportunity, I will wait.
Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Problem initializing the uos library in the service

fredvs
Administrator
This post was updated on .
Hello Andrew.

I have created a service following your description.

The demo uos program to load is consolesynth, that works as standalone.

Here the content of MyService.service:

[Unit]
Description=MyDescription
After=multi-user.target

[Service]
Type=idle
ExecStart=/home/fred/uos/examples/consolesynth

[Install]
WantedBy=multi-user.target

And indeed I get only silent.

I dont see why.

But using /home/fred/uos/examples/consolesynth as startup application works (in ~/.config/autostart).

May I ask you why do you need a service vs application autostart?
Reply | Threaded
Open this post in threaded view
|

Re: Problem initializing the uos library in the service

fredvs
Administrator
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Problem initializing the uos library in the service

fredvs
Administrator
This post was updated on .
Hello Andrey.

Some (good) news from the front!

This worked on my system:

1) Be sure that portaudio is installed in your system:
    $ sudo apt install libportaudio2

2) Use 'system' as library name for uos_loadlib
    uos_LoadLib('system', nil, nil, nil, nil, nil);

3) This is my /lib/systemd/system/MyService.service (adapt the directory with yours):

[Unit]
Description=MyDescription
After=multi-user.target

[Service]
Type=idle
ExecStart=+/home/fred/uos_demo/consolesynth
Restart=on-failure
RestartSec=10
KillMode=process
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target


In attachment the demo consolesynth binary using 'system' for uos_loadlib(), copy it somewhere and adapt the code of the service:

uos_demo.zip

Then do:
$ sudo systemctl daemon-reload
$ sudo systemctl enable MyService.service
$ sudo systemctl start MyService.service

To reload it do sudo systemctl restart MyService

This is the result of  sudo systemctl status MyService:

$ sudo systemctl status MyService

● MyService.service - MyDescription
     Loaded: loaded (/lib/systemd/system/MyService.service; enabled; vendor preset: enabled)
     Active: active (exited) since Fri 2024-01-26 03:18:54 CET; 8min ago
    Process: 12377 ExecStart=/home/fred/uos_demo/consolesynth (code=exited, status=0/SUCCESS)
   Main PID: 12377 (code=exited, status=0/SUCCESS)
        CPU: 475ms

ene 26 03:18:54 fred-IdeaPad consolesynth[12377]: ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ene 26 03:18:54 fred-IdeaPad consolesynth[12377]: ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ene 26 03:18:54 fred-IdeaPad consolesynth[12377]: ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ene 26 03:18:54 fred-IdeaPad consolesynth[12377]: Cannot connect to server socket err = No such file or directory
ene 26 03:18:54 fred-IdeaPad consolesynth[12377]: Cannot connect to server request channel
ene 26 03:18:54 fred-IdeaPad consolesynth[12377]: jack server is not running or cannot be started
ene 26 03:18:54 fred-IdeaPad consolesynth[12377]: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ene 26 03:18:54 fred-IdeaPad consolesynth[12377]: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ene 26 03:18:58 fred-IdeaPad consolesynth[12377]: Result of loading (if 0 => ok ) : 0

--------------------

I hope you will be able to do it with your application.
It seems that systemctl does not allow to libraries that are not from the system.
   
Fre;D
   
Reply | Threaded
Open this post in threaded view
|

Re: Problem initializing the uos library in the service

Andrey
In reply to this post by fredvs
The program must work before the user is authorized.
Reply | Threaded
Open this post in threaded view
|

Re: Problem initializing the uos library in the service

fredvs
Administrator
>The program must work before the user is authorized.

And?
Sorry I dont understand the problem, please explain.
The demo that I give in previous post is not ok for you?
Reply | Threaded
Open this post in threaded view
|

Re: Problem initializing the uos library in the service

Andrey
Your option didn't help. It didn't work for me.
Perhaps it was necessary to run my service on behalf of a simple user.

I figured out what the reason was.
By default, pulseaudio works in user mode and starts when the user is logged in. To use it in service mode, you need to run it as a service. But at the same time, it is still not possible to load external libraries, only "System".

I will experiment.
Reply | Threaded
Open this post in threaded view
|

Re: Problem initializing the uos library in the service

fredvs
Administrator
Hello Andrey.

The test I have done was as "simple" user, not as "root" user.
After login as "fred" user, the service is loaded and I can hear the sine-wave.

Are you trying it as "root" user (I did not try yet)?

Maybe this could help:

To have more infos of the status of the service:

$ journalctl -xeu MyService.service

And to enable the service:

$ sudo systemctl --global enable MyService.service
Reply | Threaded
Open this post in threaded view
|

Re: Problem initializing the uos library in the service

Andrey
I also ran a test and started the service as "user1".
My service has intercepted my external sound cards and other users cannot see them. But it suits me fine.
My mistake was that I was running the service as "root".
Reply | Threaded
Open this post in threaded view
|

Re: Problem initializing the uos library in the service

Andrey
Fred, thank you so much for your help!
Reply | Threaded
Open this post in threaded view
|

Re: Problem initializing the uos library in the service

fredvs
Administrator
Thanks to have find the solution!

It will surely help others.

Fre;D
12