You are not logged in.

#1 2011-04-03 20:23:57

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

The right way to start app at user's login

Hi, all.
I've been using ArchLinux for a long time, but still don't know, how to start application on user login both into text terminal and into X.

Apparently, I can't use system wide startup files, like rc.local, profile, etc, since app has to be started only for specific user.
I can't use .xinitrc file, since application should be started on textual login also.
I've seen, that applications started from bashrc files sometimes

if [ -z pidof app ]; then run app; fi

But that seems weird to me. Why should I run application from bash configuration file?

So what is the right way to start application on user's login?

Thanks

Offline

#2 2011-04-03 21:27:48

rex099
Member
Registered: 2011-04-01
Posts: 7

Re: The right way to start app at user's login

Well idk if this is what you are looking for but, when i wanted to start vnc on startup i edited the /etc/rc.local file. This is on system start not user login i think...

Offline

#3 2011-04-03 22:19:57

neutrix
Member
From: Bristol, UK
Registered: 2009-08-29
Posts: 64
Website

Re: The right way to start app at user's login

I personally use .bash_profile in the home directory of the user that you want the program to run for. This is executed on login and not every time a terminal is opened. If you want something to run every time a terminal is opened put it in .bashrc. Hope this helps.

Offline

#4 2011-04-04 07:08:42

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: The right way to start app at user's login

neutrix, thanks. I thought .bash_profile has pretty the same purpose as .bashrc.
Currently I'm not at home, so will try this later, and then mark this thread solved if success.

Offline

#5 2011-04-04 07:17:31

the_isz
Member
Registered: 2009-04-14
Posts: 280

Re: The right way to start app at user's login

neutrix' answer is right if your user is logging in on a terminal. If you want
an application to start on a graphical user login (e.g. via {x,k,g}dm), then the
answer is: depends on your desktop environment.

For instance, xdm automatically executes the .xinitrc file once the user has
successfully logged in. There, you are supposed to start your desktop
environment (e.g. Openbox, Xfce or a tiling one) and there would be the very
best place to start any additional GUI applications, too.

I guess kdm or gdm have similar options, too, but they tend to delegate this
functionality to the started desktop environment.

Beware of the following: A non-GUI application is not automatically closed upon
graphical logout. If you start such an application, you are also in charge of
killing it, because it is not automatically attached to your session.

Personally, I set up everything in my .xinitrc, which then looks like this:

# Start non-GUI and GUI applications in background

# Start desktop environment (without using 'exec'!)

# Kill non-GUI applications

I hope this helped you. For more details, you need to tell what login manager
and what desktop environment / window manager you are using.

Offline

#6 2011-04-04 09:03:23

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: The right way to start app at user's login

the_isz,
I need some applications to start on any kind of login (graphical or on terminal).

For example, I want mpd to start with login (both to terminal or x session). I can't use mpd as daemon, because there are another users on this machine and they will have to listen to my music if mpd started as root on system startup. So, currently I have entry for mpd and mpdscribble in .bashrc, that is not fully right I believe.

I don't think, my DE matters in this case, but if so, I use KDE.

P.S. this topic is not about something I really need. I can start all these programs automatically in KDE and by hand in terminal, when I need them or even leave things as is. This is just a plain curiosity smile

Last edited by eDio (2011-04-04 09:03:40)

Offline

#7 2011-04-04 10:14:24

the_isz
Member
Registered: 2009-04-14
Posts: 280

Re: The right way to start app at user's login

eDio wrote:

I can't use mpd as daemon, because there are another users on this machine and they will have to listen to my music if mpd started as root on system startup.

I think you either have a small misconception here or haven't formulated
properly. mpd is always a daemon (hence the name), what you mean is you don't
want a system daemon but a session daemon. That is no problem: You can easily
run mpd as your desktop user, e.g. reading a config from your ~/.config
directory.

eDio wrote:

I need some applications to start on any kind of login (graphical or on terminal).

That is quite difficult, I guess. I'm not exactly sure at which point the
.bash_profile file is sourced, but I am sure that it's not sourced at graphical
login. The same accounts for bash_logout and the graphical logout.

For KDE, the "proper" way of executing commands at startup and shutdown is
probably something along this here: KDE Autostart

The problem of automatically shutting down non-GUI programs when logging out of
a graphical environment persists, but I'd hope KDE has something for this, too.

As to terminal login: You could see bash_profile and bash_logout as the
terminal's way of managing your session, but setting those up will most probably
interfere with your graphical environment setting up the same.

As you probably already noticed, I can't really come up with a solution for
this, but I try to help by improving your understanding of graphical and
terminal sessions and hope it's working smile

Offline

#8 2011-04-04 21:18:44

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: The right way to start app at user's login

I think you either have a small misconception here or haven't formulated
properly. mpd is always a daemon (hence the name), what you mean is you don't
want a system daemon but a session daemon.

Yep, exactly. I meant, that I can't start it from rc.conf.

I'm not exactly sure at which point the .bash_profile file is sourced, but I am sure that it's not sourced at graphical login.

I've just tried, and my mpd started playing on graphical login. Maybe that happens, because I have yakuake in KDE autostart, hence bash instance started together with graphical session... Anyway, putting that to .bash_profile allowed me to get mpd playing at login.

if [ -z $(pidof mpd) ]
then
        mpd > /dev/null &
fi

Played a bit more around this and found, that putting that to .bash_logout "turns off" mpd on logout from terminal, but not from X.

if [ -n $(pidof mpd) ]
then
        killall mpd
fi

Also I've noticed significant X login time increase. Don't know if that caused by starting mpd from bash_profile.

Last edited by eDio (2011-04-04 21:33:03)

Offline

Board footer

Powered by FluxBB