DebianThis forum is for the discussion of Debian Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What would be the simplest way to launch a script during the boot or desktop startup process in debian?
The script in question consists of a single command (ifup wlan0) to connect the wifi and requires root privileges.
My system is debian testing, slim login manager, and jwm as window manager.
I have tried the following:
A- creating the .service way with systemd. It starts the script, but turns it off at desktop login, can't figure out why.
B- using the startup command in Jwm, but it fails I assume because launching ifup requires root privileges.
C- put the command in the .bashrc file. same as the above
D- place the script in the /etc/rc5.d directory.
I'm not using network manager, the point of my script is actually to avoid using it.
The script itself works fine, I can launch it manually from the terminal.
What I need is a way to execute the script when the machine boot.
jwm autostart is B in my list, but it does not seem to work.
You can create a systemd service to run a rc.local script which will by default run with root privileges. I know other distributions have a rc-local service.
In case anyone else needs to know, this is what eventually worked.
a- created a /etc/rc.local file
b- chmoded it 755
c- in the rc.local file I put:
Code:
#!/bin/sh -e
# This script is executed at the end of each multiuser runlevel
/path/to/my/script
exit 0
Of everything showed in this thread, this solution seems the most simple, to me. I want a script to be run at every boot, and it must be after all partitions in fstab are mounted.
I have read that rc.local is deprecated, and systemd should be used, instead. But systemd is much strange, i think. I do not want to run a service. I just want to run a script, and it will finish quickly. It only requires the file systems to be mounted.
Right now, i am using Debian 9. But it should be soon updated to Debian 11. So, the solution should work on both.
I have read that rc.local is deprecated, and systemd should be used, instead. But systemd is much strange, i think. I do not want to run a service. I just want to run a script, and it will finish quickly. It only requires the file systems to be mounted.
It's a bullet you will have to bite evtl., unless you deliberately start using non-systemd distros.
There's a good primer on writing your own services here.
Not every service runs as a daemon, it can be made to run only once at bootup. IIRC that's even the default. Dependency checking is even easier than with simple shell scripts, as it only requires a configuration option to be set.
FWIW, on Debian 9, /etc/rc.local Should(tm) still work.
This archlinux documentation you sent has so many warnings of missing things, that i prefer not to use it.
I found that systemd has several types of units to have. One of them is "service". A command, or a set of commands, is not among the unit types listed in this page.
So, how should a unit be created for running a set of commands? I am having trouble to find a full example of this.
How to write, in the new service file, the idea of "run this after fstab things are mounted"?
A strange fact in my system: Teamviewer has the file /etc/systemd/system/teamviewerd.service , which should be enough (for what i have read about systemd), but it also has /etc/systemd/system/multi-user.target.wants/teamviewerd.service . Why?
Some people i found say to "look at the units installed in your system to see examples". I see no example of what i want: a unit created for running a set of commands.
This archlinux documentation you sent has so many warnings of missing things, that i prefer not to use it.
I think you misunderstand the concept of a wiki, and also have never heard of archwiki's reputation.
But hey, suit yourself.
¯\_(ツ)_/¯
I'm also beginning to understand why you always have such problems solving your problems, and require full handholding even after 10+ years of Linux... if you continually dismiss the best resources.
2021.09.07 18:04:53 [ 0] eu@compo: /usr/lib/systemd
$ grep -lrw oneshot /usr/lib/systemd/{system,user}/*.service
grep: /usr/lib/systemd/system/*.service: Arquivo ou diretório
inexistente
/usr/lib/systemd/user/systemd-tmpfiles-clean.service
/usr/lib/systemd/user/systemd-tmpfiles-setup.service
2021.09.07 18:05:20 [ 2] eu@compo: /usr/lib/systemd
$ cat /usr/lib/systemd/user/systemd-tmpfiles-clean.service
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or
modify it
# under the terms of the GNU Lesser General Public License as
published by
# the Free Software Foundation; either version 2.1 of the
License, or
# (at your option) any later version.
[Unit]
Description=Cleanup of User's Temporary Files and Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)
DefaultDependencies=no
Conflicts=shutdown.target
Before=basic.target shutdown.target
[Service]
Type=oneshot
ExecStart=systemd-tmpfiles --user --clean
SuccessExitStatus=DATAERR
IOSchedulingClass=idle
Slice=background.slice
2021.09.07 18:05:40 [ 0] eu@compo: /usr/lib/systemd
$ cat /usr/lib/systemd/user/systemd-tmpfiles-setup.service
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or
modify it
# under the terms of the GNU Lesser General Public License as
published by
# the Free Software Foundation; either version 2.1 of the
License, or
# (at your option) any later version.
[Unit]
Description=Create User's Volatile Files and Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)
DefaultDependencies=no
Conflicts=shutdown.target
Before=basic.target shutdown.target
RefuseManualStop=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=systemd-tmpfiles --user --create --remove --boot
SuccessExitStatus=DATAERR
[Install]
WantedBy=basic.target
2021.09.07 18:05:50 [ 0] eu@compo: /usr/lib/systemd
$
How did you find that thing of "one shot"? I see 'ExecStart' with one command. To make it execute more than one command, will i always have to put them scripts, and save these scripts somewhere in the $PATH?
How did you find that thing of "one shot"? I see 'ExecStart' with one command. To make it execute more than one command, will i always have to put them scripts, and save these scripts somewhere in the $PATH?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.