Create shell script to reboot linux in case of incorrect shutdown - linux

I have Raspbian Jessie 8 running in a Raspberry Pi 3. There are 3 JavaScript services that are automatically started by PM2.
However, if the Raspberry is shutdown incorrectly, e.g., if the energy cable is removed, the services don't start.
They only start automatically if the Raspberry is shutdown properly, e.g., using sudo reboot.
I need a shell script that checks if the Raspberry was incorrectly shutdown and, if it was, to be rebooted using sudo reboot.
I saw here and here how to create a simple reboot script and here how to check if a service is running, but found nothing on how to check for an improper shutdown. Can anyone tell me how?

You can always put your services start in the legacy startup-file /etc/rc.local that is a shell script called as the very last thing in the startup. Make sure its executable.

Related

Locked out of Raspberry Pi because of crontab

I installed a crontab that runs a python script in sudo on my Raspberry Pi upon reboot. Since installing this crontab, I receive this error whenever I try to ssh into my pi:
Unable to fork: Cannot allocate memory
I think this is because my python script hogs all the RAM on the pi so that it can't start a new ssh session. What can I do to get back into my pi without resetting the SD card?
Try logging into the raspberry pi directly using the console. That may have sufficient memory to log in.
If that fails, then if you have another raspberry pi sd card or linux machine, and a spare sdcard reader, you can mount your faulty sdcard on the other machine, and edit the crontab files directly to remove the crontab.

How can I make a program to run as service in Linux

Thanks for looking into my question.
I am running tomcat as windows service in windows machine. how can I achieve the same on linux machines.
it should start automatically after reboot.
Thanks,
R Dama.
If you install Tomcat from a Linux distribution package, it will usually include an init script which will start it as a daemon via a start stop script. You can create a script for it manually otherwise. See https://www.linux.com/learn/managing-linux-daemons-init-scripts

Run a program as a service on Debian/Linux

I have an older jetty server I want to turn into as a service on a Debian OS. It should start automatic each time I restart the computer.
Manually I start the server with the two following commands:
root#myserver:/# cd /opt/jdk/jetty
root#myserver:/opt/jdk/jetty# java jetty
Anyone know how to do this ?
If you want to start any program on booting you can add that entry in rc.local.
java /opt/jdk/jetty/jetty
It will start on reboot

Screen tool on Galileo

I have compiled and installed screen tool on Galileo running on Yocto.
http://www.gnu.org/software/screen/
When I run the tool everything is OK, I can create many sessions. However when I close the terminal all my sessions are closed (when I do "screen -ls" from other terminal there are no sockets). This is not happening in any other Linux distribution.
Regards,
Yevgeniy
Are you running screen from inside a ssh connection? There was a bug in earlier releases of the devkit where on disconnect systemd killed all processes started by the daemon, which isn't what you want. This has been fixed so upgrading your image should be sufficient.
If you can't get the upgrade, the fix is to add "KillMode=process" to the end of /lib/systemd/system/ssh#.service.

Stopping or restarting networking results in GUI changes

I've observed this behaviour in both Linux Mint 15 and 16 Cinnamon on the same machine. When I use service to stop networking, like so
sudo service networking stop or restart
it's like the GUI becomes more "basic." I'm new to Linux, so forgive my ignorance, but it seems like there's another window manager on top of a more barebones one, and for some reason that process is stopped when I stop networking.
I can restart or stop network-manager without any GUI changes, and it results in my networking being reset or stopped. Why can't I mess with networking?
Maby this will help?
http://forums.linuxmint.com/viewtopic.php?t=92488&f=42
sudo service network-manager stop
sudo rm /var/lib/NetworkManager/NetworkManager.state
sudo service network-manager start

Resources