You are not logged in.

#1 2013-09-05 07:11:48

mafrek
Member
Registered: 2013-09-05
Posts: 9

how autostart Interactive program at boot before tty appears

I'm coming from Ubuntu to Arch Linux, I'm trying to autostart an interactive program written in C++ at boot before tty1 appears.
I have created a file called /etc/systemd/system/myapp.service with the following contents:

[Unit]
Description=myapp

[Service]
Type=oneshot
ExecStart=/home/xxx/myapp.exe start
StandardOutput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
And then run
sudo systemctl enable myapp

Unfortunately, it does not work as expected:
1. I can't interact with myapp
2. I do not want tty1 to appear until the program ends

Last edited by mafrek (2013-09-05 07:30:45)

Offline

#2 2013-09-05 10:50:33

mafrek
Member
Registered: 2013-09-05
Posts: 9

Re: how autostart Interactive program at boot before tty appears

now i get my app working before tty appears
/etc/systemd/system/myapp.service now contents:

[Unit]
Description=myapp
After=sysinit.target

[Service]
Type=oneshot
StandardOutput=tty
RemainAfterExit=yes
ExecStart=/home/xxx/myapp.exe start

[Install]
WantedBy=multi-user.target



But still I can not interact with my program


my simple c++ code :

#include <iostream>
int main(){ std::string str;
std::cout << "############" << std::endl;
std::cout << "Enter Youre Name: ";
std::getline (std::cin,str);
std::cout << "Welcome "<< str << std::endl;
std::cout << "############" << std::endl;
return 0;
}

Offline

#3 2013-09-05 11:01:11

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,031
Website

Re: how autostart Interactive program at boot before tty appears

How do you intend to interact with it if the tty hasn't been initialized?  That code does not replicate (a)getty's behavior, but assumes that it has already been done.

If you are writing your own login program, you still need something to set up the tty - this is what {a,min,)getty is for.  With some of these including agetty, you can specify an alternate login progam with the -l parameter, wich looks like what you are trying to do.

Or perhaps you just want auto login and want to customize /etc/issue.

The big question then, is what are you really trying to do?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#4 2013-09-05 14:46:07

mafrek
Member
Registered: 2013-09-05
Posts: 9

Re: how autostart Interactive program at boot before tty appears

i just hope to execute my above simple c++ code at bootup And interaction with it.
I've done this before, under ubuntu with init technique but i don't know do that in arch linux.

apology for my poor english.
thank u

Offline

#5 2013-09-05 15:02:48

progandy
Member
Registered: 2012-05-17
Posts: 3,491

Re: how autostart Interactive program at boot before tty appears

I guess a good idea would be to run your application with rungetty or maybe agetty with --skip-login and --login-program set to your binary.
You could also look at the code in ask-password-api in systemd I guess.
http://cgit.freedesktop.org/systemd/sys … word-api.c

Last edited by progandy (2013-09-05 15:08:53)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#6 2013-09-05 15:41:37

mafrek
Member
Registered: 2013-09-05
Posts: 9

Re: how autostart Interactive program at boot before tty appears

mr.progandy
rungetty in arch ! How install it , How does it?

Offline

#7 2013-09-05 16:14:45

progandy
Member
Registered: 2012-05-17
Posts: 3,491

Re: how autostart Interactive program at boot before tty appears

mafrek wrote:

mr.progandy
rungetty in arch ! How install it , How does it?

It is in the AUR.
You might not need it, though. systemd can open the tty for you

User=nobody
StandardInput=tty
StandardOutput=tty
StandardError=tty (or maybe journal+console to log error data)

Last edited by progandy (2013-09-05 16:18:54)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#8 2013-09-05 19:22:06

mafrek
Member
Registered: 2013-09-05
Posts: 9

Re: how autostart Interactive program at boot before tty appears

thank you . thank you . thank you .
the secret thing in magic line `StandardInput=tty`
my final  /etc/systemd/system/myapp.service
contents:

[Unit]
Description=myapp
After=sysinit.target

[Service]
Type=oneshot
StandardInput=tty
StandardOutput=tty
RemainAfterExit=yes
ExecStart=/home/xxx/myapp.exe start
ExecStop=/home/xxx/myapp.exe stop

[Install]
WantedBy=multi-user.target


AND i disable tty1
sudo systemctl disable getty@tty1.service

Now tty1 is my app (-:

Another problem )-:

ExecStop=/home/xxx/myapp.exe stop

not working, i want run myapp with stop parameter on shutdown/reboot system


thanks for ( Trilby, progandy )

Last edited by mafrek (2013-09-06 09:43:13)

Offline

#9 2013-09-06 09:37:35

mafrek
Member
Registered: 2013-09-05
Posts: 9

Re: how autostart Interactive program at boot before tty appears

progandy wrote:

I guess a good idea would be to run your application with rungetty or maybe agetty with --skip-login and --login-program set to your binary.
You could also look at the code in ask-password-api in systemd I guess.
http://cgit.freedesktop.org/systemd/sys … word-api.c


Wonderful , This advanced,  Is not the time to use this but realy linux is great, awesome

thank u

Offline

Board footer

Powered by FluxBB