Launch script at startup
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. nothing worked so far. suggestions? |
are you using network-manager?
is there the network manager applet in your system tray? i'm sure jwm has its own autostart mechanism, did you check that out? |
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.
https://www.itechlounge.net/2017/10/...l-in-debian-9/ |
michaelk,
I'll try what's suggested in the link, but wonder if there shouldn't be a simpler way. |
A cron job that executes at startup i.e. @boot as a system cron task should also work.
|
Thanks everyone for the input.
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 |
Quote:
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. What do you say? |
Quote:
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. |
Quote:
Code:
grep -lrw oneshot /usr/lib/systemd/{system,user}/*.service Code:
/usr/lib/systemd/system/grub-common.service |
Quote:
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. |
Quote:
Code:
|
Quote:
|
As a FYI the systemd rc-local.service still exists in debian 11.
|
All times are GMT -5. The time now is 09:40 AM. |