Automaticly run xinit from rc.local as different user - linux

I'm working on some tuning of my raspberry. So I decided that midori should start automaticly after autologin.
With startx it works without problems, but X is still to ressource hungry. So I'll start midori with xinit and matchbox.
As test, I use as user "pi" this command "xinit ./home/pi/startmidori.sh" and it works.
So I'll put this into my rc.local file.
There is the command "su -l pi -c xinit ./home/pi/startmidori.sh", this doesn't work. I don't know why, but xinit exit immediately after starting.
How can I solve this? In guides I find this kind of solution, but for it doesn't work. I tryed to run it as root but it doesn't work, too. I've no idea why.

Check this for more information: Running X from The X Window User HOWTO
In general you always need a wrapper and you must run X with root, since it needs raw access to hardware devices.
So I suggest you to install lightweight display manager like LightDM if possible it has almost no footprint and then easy you can set it up to auto login with desired user and run desired window manager like matchbox in your case.

Related

Make chosen version of Elasticsearch run as a service in Linux

I have an issue with later versions of ES, so have to use 7.10.2 currently.
This means that the previous method I used to install ES as a service, i.e. apt-get, doesn't work You can't choose an older version this way: it currently installs 7.16.3.
So I followed the procedure on this page for 7.10: everything worked: I was able to run ES as an app and also as a "daemon". Clearly I could simply put the "daemon" startup line in a script which runs on boot.
But what's the optimum way of turning this "daemon arrangement" into a service which you can control with systemctl, and which starts automatically when the machine boots?
PS I don't want to get involved with Docker. I'm sure that's a useful thing but I'm convinced there is a simpler way of doing it, using available Linux sys tools.
I found a workaround... this doesn't in fact create a service of the "systemd" type which can be controlled by systemctl. There seem to be one or two problems which make this non-trivial.
1) You can't start ES as root! I assume (not sure) that most services are being run by root. Anyway this was something I couldn't find a solution to.
2) I am not sure whether a shell script file called by a service is allowed to end... or should continue endlessly: initially I thought this would be sufficient. This is a shell script (run_es_daemon.sh) which does indeed start up ES (as a daemon process) when run by manually in a terminal. There is no issue to do with the fact that the script ends and you then close the terminal: the daemon process continues to run:
#!/bin/bash
# start ES as a daemon...
cd /home/mike/Elasticsearch/elasticsearch-7.10.2
./bin/elasticsearch -d -p pid
... but it never worked using a xxx.service file in /etc/systemd/system/ (maybe because of 1) above). So I also tried adding these lines under the above ones:
while true
do
echo "bubbles"
sleep 60
done
... didn't work either.
In the end I found a simple workaround solution was to start up the daemon process by using crontab:
#reboot /home/mike/sysadmin/run_es_daemon.sh
... but I'd still like to know how to set it up as a true service, which starts at boot...

Need to reboot Xubuntu to make chgrp work?

I recently noticed a fairly strange and for me unexpected behaviour in Xubuntu 12.04 and 14.04.
I was doing the following:
Testing if my user in in the group users, with
groups $USER
This is not the case by default. So I add my user to this group:
sudo usermod -a -G users $USER
I the can check the file /etc/group and will see my user added in the entry.
I then would like to give the group users access to some files, in my example the www and cgi-bin directory:
sudo chgrp users /var/www /usr/lib/cgi-bin
I also want that my group can write into the directories:
sudo chmod g+w /var/www /usr/lib/cgi-bin
I would assume, that I can now create a file in those directories, but I can't. Neither by commandline, nor by the standard filebrowser from Xubuntu.
Somewhere I read, that I need to logout from the terminal to make it work, so I close and reopen the commandline terminal, but it is still now working.
But: It I reboot the whole system everything works as it should...
Seriously??? Why is this, is it a bug or a feature and are there better ways then restarting the complete OS?
(I thought the strength of Linux is exactly that you don't need to reboot all the time like in other "popular" OS)
(Note: I have not tested this on other systems as e.g. Debian yet...)
Group memberships are inherited from process to process like many other things in a unixoid environment. That means a running shell will not be affected from such changes in the account configuration. Also just opening a new terminal or shell will not show the change, since it is spawned from an already running process, ultimately from the initial process started right after the login.
You have to re-run the login process instead. Either by restarting the graphical environment, or by doing a logout/login sequence when working on the virtual terminals. Also obviously rebooting will lead to a new login process.
The only direct alternative is to spawn a new login shell explicitly: bash -l for example does the trick: it re-executes all stuff run through at login time. But note that this only effects that started shell and processes spawned from it. It does not affect other already running processes. So you have a somewhat mixed environment then...

Stop Raspberry Pi from running program at boot

I was trying to figure out how to run a program at boot, but after realizing this program is an infinite loop, I have no way of getting out, or back to the terminal. Right when I give the Pi power it just goes right to the program on a black background. I don't remember exactly what I did to make it run at boot, I believe I just added some code in a place right above something that said "exit 0" and below something that says "esac". I don't remember the command that even got me there. (I am new to the Pi and Python and have just been playing around..unsucessfully.)
If anyone could help me either delete this program or get me to be able to edit it so I can fix the infinite loop that would be great. I'd rather not have to completely over-write the sd card with a fresh raspbian. But like I said I can't do anything at boot, and Ctrl + C doesn't do anything nor Ctrl + Alt + Delete.
EDIT: When I put the SD card in my computer, I see a list of 11 files:
bootcode
cmdline
config
fixup
fixup_cd
issue
kernel
kernel_cutdown
kernel_emergency
start.elf
start_cd.elf
None of these mean anything to me...
Update: Looks like I failed to get that you want to interrupt the running bootprocess and stop the script.
The simplest idea would be to turn of the pi, unplug the sd card and plug it into your desktop, (re)move the script and boot again.
Processes spawned during boot are stored in scripts in /etc/init.d/.... These scripts are called by the init process, the first process on a Linux machine (PID:1)
But init starts not all scripts in /etc/init.d. This depends on the run level. On a debian system there are 7 run levels.
For every run level there is a folder called like:
/etc/rc0.d
...
/rc6.d
in which are softlinks to scripts from /etc/init.d are stored.
To remove a script from being executed on every boot you'll delete all links from that folders. Usually on debian systems this is done using the update-rc.d tool:
update-rc.d NAME_OF_INIT_SCRIPT remove
You should also have a look at the file /etc/rc.local
Alt + PrintScn + k to kill the process stuck running from rc.local
You can use the cmdline.txt.
First, add or modify the cmdline.txt file on your sd card. Add "init=/bin/sh", then restart your Pi, and you can see a command line prompt.
Type 'sudo nano /etc/rc.local' to edit the file, and comment or delete the line containing the error. After that restart.
I had exactly the same issue, couldn't quit the process using CTRL+C. I edited the cmdline.txt like stated above, but then the pi didn't load the necessary usb drivers for my keyboard.
So eventually I logged in over SSH to the pi, and modified my rc.local file that way.
In my case worked combination "Alt" + "F4", it stops the current session and opens the login screen
I had the same problem as explained at the beginning of this Post. My Python app was caught in an endless loop.
I tried the Ctrl+Alt+F2 Command as recommended in many posts found in Internet without any terminal window being open. Apparently, after many other trials and reboots I saw a glimpse of a Terminal window each time the loop of my application restarted. It was impossible to catch anything until I started recording the screen using the slow motion video of my mobile phone and, yes, a terminal window with the Linux prompt was active, and able to accept keyboard entries.
All I did was (almost blindly) editing the culprit file with the
sudo nano filename command
and entering some characters in order to actually corrupt such file, saving and closing it, a rebooting the Pi.
At the end of the boot, the file produced an error but the system kept ready to operate.
I was then able to fix the bug in a normal way.
It hope this may be useful to others. In my case it spared me of burning a new Raspbian and losing all my previous work.
I got myself stuck in exactly the same problem. Luckily I had the ssh enabled, apparently this is disabled by default on Raspbian Jessie, so this may not work for all.
The exit 0 is the line in /etc/rc.local where you would have added in the script that is now running in a continuous mode. If you can ssh into the Pi using Putty and the Pi's IP address then
sudo nano /etc/rc.local
Scroll down to the bottom of the file and remove the offending program, then sudo reboot
They way to prevent this issue from happening is to add an & (ampersand) to the end of the line to fork the process and run it as a separate process like so
python /home/pi/myscript.py &
as specified in https://www.raspberrypi.org/documentation/linux/usage/rc-local.md
The ampersand allows the command to run in a separate process and continue booting with the process running.

Using script to automatically start program when the system boot up (linux, shell)

Here is the situation, I'm planning to use a simple script to start a program call "STAF", when the Suse system is fully booted. I have achieved this by putting it in the "/etc/init.d/", but this script is basically executed at the background, which means that I cannot see its progress.
When the "STAF" is started this way it works but it doesn't show any working progress when its running service (for example ping, or system backup), instead if I start the "STAF" manually by running the same script whit a terminal, the working progress of "STAF" can be seen on the terminal. Its sort of like the program needs to be started with a interactive terminal, but how can I make this starting process automatic and it should imitate human opening a terminal and run the script?
Sorry if I explained it poorly because its a confusing situation. Thanks.
First, go to the KDE Startup and Shutdown options under System Settings. Then add this command as a new startup script:
konsole -e bash nameofyourscript.sh
I believe the screen utility can do what you describe. Instead of running STAF on startup, you would run screen STAF. To open that terminal, you would run screen -ls to get the screen ID, and screen -r ... to open it.
(Disclaimer: I have not tried this.)

Starting a process when Linux starts (Ubuntu)

I have a process (Spark chat client) which needs to be run when my Ubuntu boots up. For this I have done followings.
I created a run.sh file which will fire up my application (and I check it's working)
I created a symbolic link from both /etc/rc5.d/ and /etc/rc3.d/ to my run.sh file. (A symbolic link is also working fine)
But my processes don't start up when my machine boots. (Is this the way to do it or am I doing the wrong thing here?)
I'm running on Ubuntu 10.04 LTS (Lucid Lynx).
Your solution would've worked in most Linux distributions. However, Ubuntu never goes past runlevel 2.
Just in case, this means the contents of rc?.d with ? > 2 are not used unless you manually raise the runlevel as root. Use rc2.d :)
The symlinks you created in /etc/rc5.d/ and /etc/rc3.d/ should be named S##name. S is for start, and the number ## gives an order in which the scripts are run.
Note also that the symlinks in these directories usually points to the actual script located in /etc/init.d/.
It looks like you want to run an X program when a user logs in, not a service on startup. Remember, in Linux there is no GUI; X is a program that runs to display graphics on the screen.
You likely want to set up a program to start on KDE/Gnome login. Each has their own way to do it, but is generally boils down to pointing at a script and saying "Run this."
Put the command to run that script in the /etc/rc.local file. I think it will run each time you log in to the system.

Resources