hello_maxish
Posts: 36
Joined: Thu Sep 01, 2022 12:22 pm

auto start a terminal with two lines of code

Thu Dec 01, 2022 6:46 pm

I would like to do the following:

when Pi is boot the command line will be open then two lines will be executed one after the other:

Code: Select all

sudo systemctl stop my_puredata.service
then

Code: Select all

sudo systemctl start my_puredata.service
Is this possible?
How can I do so?

NotRequired
Posts: 357
Joined: Sat Apr 29, 2017 10:36 am
Location: Denmark

Re: auto start a terminal with two lines of code

Thu Dec 01, 2022 6:57 pm

The two commands you posted does the same as:

Code: Select all

sudo systemctl restart my_puredata
But why would you need to restart it after boot?
Glowing in the dark!

hello_maxish
Posts: 36
Joined: Thu Sep 01, 2022 12:22 pm

Re: auto start a terminal with two lines of code

Thu Dec 01, 2022 7:18 pm

NotRequired wrote:
Thu Dec 01, 2022 6:57 pm
The two commands you posted does the same as:

Code: Select all

sudo systemctl restart my_puredata
Is it complicated to make pi run this command on boot?
How can I do so?
NotRequired wrote:
Thu Dec 01, 2022 6:57 pm

But why would you need to restart it after boot?
For some reason only after restarting the service the pd patch is loading. if I don't do so it keep crashing

NotRequired
Posts: 357
Joined: Sat Apr 29, 2017 10:36 am
Location: Denmark

Re: auto start a terminal with two lines of code

Thu Dec 01, 2022 7:23 pm

Do you have any detailed info / logs about the errors? Sounds like the service is started before a required feature is available and fixing that would be the better option..

EDIT: And what exactly is "pd patch"?
Glowing in the dark!

hello_maxish
Posts: 36
Joined: Thu Sep 01, 2022 12:22 pm

Re: auto start a terminal with two lines of code

Thu Dec 01, 2022 7:40 pm

PD is software you can make music with. Patch is like a file that make certain stuff. In my case it is playing back some audio files.

here is the error: https://imgur.com/a/KcsbRuK

When I start the same patch using the same script but without a USB audio interface is working just fine.

When I start the same patch with a USB audio interface but using the autostart file: "sudo nano /etc/xdg/lxsession/LXDE-pi/autostart"
Is also working just fine.

But the combination of the USB audio interface and the service script is just not working

NotRequired
Posts: 357
Joined: Sat Apr 29, 2017 10:36 am
Location: Denmark

Re: auto start a terminal with two lines of code

Thu Dec 01, 2022 7:51 pm

I cannot se the source of the systemd service, but you could try to add:

Code: Select all

[Unit]
...
After=sound.target

...
Glowing in the dark!

hello_maxish
Posts: 36
Joined: Thu Sep 01, 2022 12:22 pm

Re: auto start a terminal with two lines of code

Thu Dec 01, 2022 8:01 pm

service script is:

Code: Select all

[Unit]
Description=My PureData service

[Service]
Type=simple
LimitNOFILE=1000000
ExecStart=/usr/bin/puredata -nogui -open  /home/pi/mypatch.pd
WorkingDirectory=/home/pi
User=pi
Group=pi
Restart=always
# Restart service after 10 seconds if service crashes
RestartSec=10

[Install]
WantedBy=multi-user.target
where should I add:

Code: Select all

After=sound.target
What does After mean?

User avatar
thagrol
Posts: 8557
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: auto start a terminal with two lines of code

Fri Dec 02, 2022 12:32 am

NotRequired wrote:
Thu Dec 01, 2022 7:51 pm
I cannot se the source of the systemd service, but you could try to add:

Code: Select all

[Unit]
...
After=sound.target

...
That may not help especially if audio I/O is required. RPiOS uses pulse audio which in the default configuration is not started until a user logs into the desktop.

It may be necessary to run pulse audio in systemwide mode. Refer to the pulseaudio docs for that (google et al know where to find them).
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
thagrol
Posts: 8557
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: auto start a terminal with two lines of code

Fri Dec 02, 2022 12:35 am

hello_maxish wrote:
Thu Dec 01, 2022 8:01 pm
What does After mean?
It means don't start (or try to start) this service before the listed targets have been reached orthe listed services have been started. It's often used in conjunction with "Required="

Have a read of the systemd docs for more (again a web search will find them).

If you've not seen it, you may find Running A Program At Start Up A Beginner's Guide to be of interest.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

hello_maxish
Posts: 36
Joined: Thu Sep 01, 2022 12:22 pm

Re: auto start a terminal with two lines of code

Fri Dec 02, 2022 7:19 am

Is there anything wrong with open the PD file using the autostart folder

Code: Select all

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
I might need to disabled completely the builtin Pi audio card?

User avatar
thagrol
Posts: 8557
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: auto start a terminal with two lines of code

Fri Dec 02, 2022 1:43 pm

hello_maxish wrote:
Fri Dec 02, 2022 7:19 am
Is there anything wrong with open the PD file using the autostart folder

Code: Select all

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
I might need to disabled completely the builtin Pi audio card?
Yes. That will start it at every desktop login by any user. However that may not matter to you. Use your target user's autostart file as outlined in section 5.1.1 of the document I linked to above.

If you do go the autostart route disable your systemd service or you'll likely get multiple copies running.

Can't comment on whether you need to disable the built in audio or not.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

Return to “Raspberry Pi OS”