Tomcat starts after issuing 'stop' command - linux

I am seeing very confusing behavior in my tomcat.
I execute:
/usr/libexec/tomcat/server stop
But instead of stopping tomcat restarts. I issue the command a 2nd time, and then it actually stops. I have tried searching but have not come up with a good way to search 'restarts after stop'. Almost all results talk about scripts to restart tomcat, and stop/start functionality.

You can stop tomcat with this command: your/path/tomcat/bin/./catalina.sh stop and your/path/tomcat/bin/./catalina.sh start to start the server.
If you use linux and your catalina.sh does not have executable permission you need execute this: chmod +x catalina.sh before

Related

Auto startup my source code in ubuntu

My python source file automatically starts while I boot the system. I tried in init.d and some other shell scripts, but its not working. Note (I also make the executable file), but it doesn't work.
Please help.
There are a number of other posts covering this topic, notably here
Put this in /etc/init (Use /etc/systemd in Ubuntu 15.x)
mystartupscript.conf
start on runlevel [2345] stop on runlevel [!2345] exec /path/to/script.py
By placing this conf file there you hook into ubuntu's upstart service that runs services on startup.
manual starting/stopping is done withsudo service mystartupscript start and sudo service mystartupscript stop
There is another solution here also also

How to trigger a custom script to run whenever a specific systemd service restarts

I wish to know how can I schedule a custom script to run whenever I restart a service.
My use case is that I have to run several commands whenever I restart my Tomcat Service. I want to know if there is a way I can write a script and schedule it to run whenever I restart the Tomcat service.
I have setup the tomcat script as a systemd service. I am using Cent OS 7 x64.
I have been able to achieve this by creating another service and incorporating the Tomcat service's start stop in the new service. The new service acts as a wrapper service which first starts tomcat and then executes the commands that we need to run as soon as tomcat starts.
Then while stopping, it stops tomcat and runs clean up commands.
EDIT: I found another way of doing this on unix & linux stackexchange.
Simply create an new systemd .service file in /etc which includes and overrides part of the one in /lib. For example, create /etc/systemd/system/tomcat.service to contain
.include /lib/systemd/system/tomcat.service
[Service]
ExecStartPre=/home/meuh/myscripttorun some pre args here
ExecStartPost=/home/meuh/myscripttorun some post args here
Any ExecStartPre lines will be executed before the ExecStart line, and similarly any ExecStartPost will run after tomcat has started.

how to automatically restart a node server?

We are finishing development of a project, the client is already using it but occasionally some errors occur - crashing the server.
I know I could register a service as 'upstart' script on linux, in order to have my node service restart when it crashes.
But our server is running other stuff, so we can't restart it.
Well, actually, while writing, I realize I have two questions then:
Will 'upstart' work without having to reboot? Something is just whispering yes to me :)
If not, what other option would I have to 'respawn' my node server when it crashes?
Yes, upstart will restart your process without a reboot.
Also, you should look into forever.
PM2 is a Production process manager for Node.js app.
If your focus for automatic restart is an always running application, I suggest to use a process manager. Process manager, in general, handles the node process(es if cluster enabled), and is responsible for the process/es execution. PM leans on the operative system: your node app and the OS are not so strinctly chained because the pm is in the middle.Final trick: put the process manager on upstart. Here is a complete performance improvement path to follow.
Using a shared server and not having root privileges, I can't download or install any of the previously mentioned libraries. What I am able to do is use a simple infinite bash loop to solve my issue. First, I created the file ./startup.sh in the base directory ($ vim startup.sh):
#!/bin/bash
while:
do
node ./dist/sophisticatedPrimate/server/main.js
done
Then I run it with:
$ bash startup.sh
and it works fine. There is a downside to this, which is that is doesn't have a graceful way to end the loop (at least not once I exit the server). What I ended up doing is simply finding the process with:
$ ps aux | grep startup.sh
Then killing it with
$ kill <process id>
example
$ kill 555555

Linux command to restart application

For example - i have process id which i want to restart. What command i should use to restart this process application ? I didn't find something about it(
Thanks!
You can find very similar question at Restart process script linux.
Linux doesn't have general command for restart, normally you should kill your process and start it over. However, if your process has been started as a service, i.e. it's contained in /etc/init.d/ directory, then you can do the following:
/etc/init.d/SERVICE_NAME restart
or
service SERVICE_NAME restart

Cannot get my Upstart script to run Node.js and Forever when server restarts

I've been setting up my server recently and today I had to restart it... then I realised all of my Node apps I had running weren't running anymore. I'm using Node Forever module to keep the apps running, but then I realised I still need to have them starting when my server restarts or shut downs and powers up again.
I have been researching the best way to do this, but what I'm trying just doesn't seem to work. I've created an Upstart script in my /etc/init/ folder on my Ubuntu Server 10.04LTS remote server and tried restarting and it doesn't seem to do anything. Nothing is getting listed when I run forever list.
Here is my current Upstart script I was trying out today:
#/etc/init/myapp.conf
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
script
exec sudo /usr/local/bin/node /var/www/myapp/myapp.forever.js
end script
I use Forever in a Node script as I find it easier to configure it how I want. It's confirmed that the script runs just fine if I do this outside the script, there is just something wrong with the Upstart script itself. It seems to have the same permissions as all the other Upstart scripts in /etc/init/ folder.
As an additional note, I have gone through almost all the answers I could find here on StackOverflow, and that it how I got together the script that I have at present.
UPDATE:
With Tom's answer, I have now tried:
#/etc/init/myapp.conf
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
exec sudo /usr/local/bin/node /var/www/myapp/myapp.forever.js
But it's still not working.
So I don't know why this isn't running when I restart my server. Please help!
This is not a very happy setup. The way upstart works is that it starts your process running it using the process id for the start command. Forever JS works similarly, it is probably inspired by Upstart.
When you try to run forever.js with upstart, the forever process you create in your upstart script exits immediately after starting. Upstart counts on having the process continue to run.
When I tried to run forever using upstart, I wound up with five different forever process running because upstart thought it had failed to start forever, and it retried five times.
Did you try doing it without the start script lines?
description "my server"
author "name"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
#respawn if you were not using forever
exec sudo /usr/local/bin/node myapp.forever.js
Source: http://caolanmcmahon.com/posts/deploying_node_js_with_upstart
I've opted to use an #reboot statement in the user's crontab file, which will execute forever on server restarts.
#reboot forever start app.js
Additional Reading - http://www.cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot/

Resources