Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #258384

Re: How to run a command / script on startup automatically in linux?

From Vincent Lefevre <vincent@vinc17.net>
Newsgroups linux.debian.user
Subject Re: How to run a command / script on startup automatically in linux?
Date 2023-05-15 21:40 +0200
Message-ID <GvMd3-98Be-1@gated-at.bofh.it> (permalink)
References <GvKkV-97s9-3@gated-at.bofh.it> <GvKuB-97vG-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 2023-05-15 13:42:52 -0400, Greg Wooledge wrote:
> On Mon, May 15, 2023 at 10:44:37PM +0530, Susmita/Rajib wrote:
> > 
> > I saved a file at "/etc/systemd/system/" named "rc-local.service" with
> > the following lines:
> > ------------------------------------------------
> 
> There's no need to do that.  Debian already ships an rc-local.service.
> 
> All you need to do is create an /etc/rc.local file, make it executable,
> and make sure it's a valid shell script (with a shebang and all that).

This is a bad idea. The /etc/rc.local file is provided by the
initscripts package. I would suggest to either install this
package and use it in the way it is intended or create your
own service.

> A GUI-related program has to be run after you launch your GUI session.
> Traditionally, this is accomplished by adding it to your .xsession file,
> if you wrote your own .xsession file.  But most Desktop Environment
> users don't do that.  They don't have a personal .xsession file at all.

The .xsession file entirely replaces the desktop environment or
window manager. See /etc/X11/Xsession.d/50x11-common_determine-startup
and the Xsession(5) man page. This is useful to run configuration
utilities before explicitly running the window manager at the end.

> Debian created another file called .xsessionrc which you can use instead,
> even if your don't use an .xsession file.

But note that programs run from .xsessionrc may be run too soon
(before other settings from /etc/X11/Xsession.d). The .xsessionrc
file should only be used to set up environment variables and things
like that.

> So, here's what I'd suggest:
> 
> 1) Get rid of your /etc/systemd/system/rc-local.service file.  It's not
>    needed, and will just cause confusion.

Agreed.

> 2) Create a ~/.xsessionrc file containing the commands you want to run
>    while starting your X session.

This depends on the commands. GUI applications like mousepad should
not be run from it. They should be run by the DE or WM. If this is
not possible, run them just before via a ".xsession" file.

> 3) Double-check that this "mousepad" command can be run in the way you're
>    running it.  Does it self-background?  If not, then you need to put
>    an ampersand after it:
> 
>    mousepad &

Note that if it is run by the DE or WM (recommended way as this
may benefit from the DE/WM features), there is probably no need
for the "&".

> See also: https://wiki.debian.org/Xsession

The man page is more detailed.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Back to linux.debian.user | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to run a command / script on startup automatically in linux? "Susmita/Rajib" <bkpsusmitaa@gmail.com> - 2023-05-15 19:40 +0200
  Re: How to run a command / script on startup automatically in linux? Greg Wooledge <greg@wooledge.org> - 2023-05-15 19:50 +0200
    Re: How to run a command / script on startup automatically in  linux? Charles Curley <charlescurley@charlescurley.com> - 2023-05-15 20:50 +0200
      Re: How to run a command / script on startup automatically in linux? Greg Wooledge <greg@wooledge.org> - 2023-05-15 21:00 +0200
        Re: How to run a command / script on startup automatically in linux? <tomas@tuxteam.de> - 2023-05-16 06:30 +0200
    Re: How to run a command / script on startup automatically in linux? Vincent Lefevre <vincent@vinc17.net> - 2023-05-15 21:40 +0200
      Re: How to run a command / script on startup automatically in linux? Greg Wooledge <greg@wooledge.org> - 2023-05-15 22:00 +0200
        Re: How to run a command / script on startup automatically in linux? Vincent Lefevre <vincent@vinc17.net> - 2023-05-15 23:10 +0200
          Editing /etc/rc.local [was: How to run a command / script on startup  automatically in linux?] <tomas@tuxteam.de> - 2023-05-16 06:40 +0200
            Re: Editing /etc/rc.local [was: How to run a command / script on  startup automatically in linux?] Vincent Lefevre <vincent@vinc17.net> - 2023-05-16 11:50 +0200
  Re: How to run a command / script on startup automatically in  linux? Charles Curley <charlescurley@charlescurley.com> - 2023-05-15 20:00 +0200
    Re: How to run a command / script on startup automatically in linux? Max Nikulin <manikulin@gmail.com> - 2023-05-16 04:40 +0200
      Re: How to run a command / script on startup automatically in linux? Max Nikulin <manikulin@gmail.com> - 2023-05-16 09:10 +0200
  Re: How to run a command / script on startup automatically in linux? Christoph Brinkhaus <c.brinkhaus@t-online.de> - 2023-05-15 20:10 +0200
  Re: How to run a command / script on startup automatically in linux? <tomas@tuxteam.de> - 2023-05-15 20:30 +0200
    Re: How to run a command / script on startup automatically in  linux? Charles Curley <charlescurley@charlescurley.com> - 2023-05-15 20:50 +0200
    Re: How to run a command / script on startup automatically in  linux? Joe <joe@jretrading.com> - 2023-05-15 21:40 +0200
  Re: How to run a command / script on startup automatically in linux? "Susmita/Rajib" <bkpsusmitaa@gmail.com> - 2023-05-16 07:50 +0200
    Re: How to run a command / script on startup automatically in linux? Vincent Lefevre <vincent@vinc17.net> - 2023-05-16 12:10 +0200
    Re: How to run a command / script on startup automatically in linux? Greg Wooledge <greg@wooledge.org> - 2023-05-16 13:20 +0200
    Re: How to run a command / script on startup automatically in linux? "Susmita/Rajib" <bkpsusmitaa@gmail.com> - 2023-05-16 14:10 +0200
      Re: How to run a command / script on startup automatically in linux? "Susmita/Rajib" <bkpsusmitaa@gmail.com> - 2023-05-18 08:10 +0200

csiph-web