Rapsberry Pi without user and auto start node program - node.js

Before posting this question i have gone through different blogs but couldn't find any good solution so posting this question.
I have raspberry pi set up with pi user.
I want to set up it without login and run node program on start up so there would not require any manual intervention.
I am not able to edit /etc/rc.local file. It gives me Can't open file to write error.
I am not able to open /etc/sudoers file as well. While opening it, it gives me error as well. So not sure what to do now. If anyone can help to solve this file issues and after that any good document to start the Pi without user and auto start node program will be so helpful.

You can't start the Pi without any user.
And you need to be root to edit this file: sudo vi /etc/rc.local (on raspbian)
There is already an auto login process at startup, for the standard pi user, so you just need to add your command line for starting node.
https://www.raspberrypi.org/documentation/linux/usage/rc-local.md

Related

Raspberry Pi boot script duplicating

I am trying to run a few scripts at each boot of the raspberry pi. I have been able to verify that when they are not configured to start automatically, I can run them, and they all work exactly as intended (and in only one instance). I have tried quite a few methods of autostarting these scripts, and I have found that using a desktop entry in .config/autostart directory to be my preferred way of doing it. I have also tried editing rc.local, crontab, systemd, and entries in .config/lxsession/LXDE-pi/autostart with no more success.
The issue is that when I have the scripts running at boot, there is a duplicate of the script running (I have it set to open a new instance of LXterminal, though there are not duplicates of the terminal). The script runs at boot just fine, but I am cannot figure out why there seems to be a "ghost" version of the script too. I have the autostart commands set to write to log files that show that the scripts are running more than once. I have also tried this on a fresh raspbian install. Could someone help me figure this out? I'm at a loss on what my issue is. This is for use of Amazon Alexa.
This is what I have in /home/pi/.config/autostart/AlexaBoot.desktop:
[Desktop Entry]
Name=AlexaBoot
Exec=lxterminal -e "/bin/bash /home/pi/Desktop/alexa_boot.sh"
Type=Application
I can post what I have in the autostarted script if necessary. Thanks.
Found a fix for this. My solution is outlined on a similar Github issue, hopefully this is able to help someone with the same issue.

Command Not Found CentOS | .bat File

Im trying to run a .bat file on my server through php popen command, ive struggled and finally got to the point where all the permissions are set correctly and now i can actually execute the file but i have a problem. In my server logs it displays
foo.bat: line 1: mstsc: command not found, referer: http://dev.example.com
The full code in the file is mstsc /v:192.168.1.1 I know this means that it doesn't recognise the command on centos but im not sure what to do to fix the problem.
The aim of this code is to open RDP for the user who requested it. Bear in mind that this code works perfectly locally on my windows OS using xampp but when i upload it to the server running CENTOS it doesnt work.
My question is
How do i fix this error and allow CENTOS to execute a command that opens an RDP window for the user
MSTSC is a Windows RDP client which is why it works on Windows.
It's not available to run on CentOS, let alone call by executing a Windows batch file! You'll need to use an alternative solution like FreeRDP and use a script like this one if you want to do this from CentOS: https://www.server-world.info/en/note?os=CentOS_7&p=x&f=5
I feel like this is exactly what you're after
http://www.jjclements.co.uk/2010/02/21/rdp-hyperlink/
It allows you run a bat file that opens windows RDP without needing to write a single line of server code. Take a look its pretty good!

Raspberry Pi stuck on script at startup

I wanted to have my Raspberry Pi update the system clock from a GPS on start up but now something has gone wrong and I can't login.
I created a bash script that calls 'sudo -i' and a few other gpsd related instructions. I pointed the /etc/profile towards the script. If I Ctrl+C to get to a prompt I get root access but the directories are listing nothing when I use the 'ls' command. If I exit from root I get stuck again. I figure that if I could delete the bash script the problem would go away but I don't know how to view that partition of the SD card on a PC. Any suggestions?
Ok, I solved the problem. There is a ext4 partition editor called ExtFS for Windows. You can view and edit an ext4 partition easily in this program. You can download it here.

Automaticly run xinit from rc.local as different user

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.

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.

Resources