I write a shell script for starting two play framework application.
cd /someDirectory
activator "start -Dhttp.port=9001"
cd /anotherDirectory
activator "start -Dhttp.port=9002"
after running the shell script, running process sleeps after starting first application (because play framework stay in shell after start command until pressing Ctrl + D)
How can I say to activator release shell after starting?
Use any process manager you want :
screen
nohup
upstart
systemd
supervisord
BTW, if this is production, you might consider using the start script created when packaging your application.
Use nohupas follows nohup ./script &. It is also useful when starting applications from remote shell.
Related
I'm using a Dockerfile that ends with a CMD ["/start.sh"]:
#!/bin/bash
service ssh start
/usr/bin/node /myApp/app.js
if for some reason i need to kill the node process, the ssh server is being closed as well (forces me to reboot the container to reconnect).
Any simple way to avoid this behavior?
Thank You.
The container exits as soon as main process of the container exits. In your case, the main process inside the container is start.sh shell script. The start.sh shell script is starting the ssh service and then running the nodejs process as child process. Once the nodejs process dies, the shell script exits as well and so the container exits. So what you can do is to put the nodejs process in background.
#!/bin/bash
service ssh start
/usr/bin/node /myApp/app.js &
# Need the following infinite loop as the shell script should not exit
while do:
sleep 2
done
I DO NOT recommend this approach though. You should have only a single process per container. Read the following answers to understand why -
Running multiple applications in one docker container
If you still want to run multiple processes inside container, there are better ways to do it like using supervisord - https://docs.docker.com/config/containers/multi-service_container/
I'm writing a simple menu using the dialog utility in a bash script.
The idea is that the menu script will run in a screen session which I can connect to over SSH (or whatever else).
I want to then use the menu to start/stop applications running on the machine. For example there might be a menu item called "Start/Stop gEdit". When it's selected, one of two things could happen:
If gEdit is not currently running, it starts it
If gEdit is currently running, it stops it
My question is, what is the best way to launch (and close) applications from my bash script? This is on Debian.
Edit: Is upstart the right choice here? It seems weird to write an upstart script for something like gEdit.
AFAIK..
You can run/stop applications from bash script the same way you do it from command line.
./ to run
kill -9 pid to close.
Debian now is using systemd Not upstart.
If you want to see if gedit is running in order to start/stop you can do something like pgrep gedit:
if [ pgrep gedit > 0 ]
echo "Something"
then
echo "Other thing"
I have a glassfish install and I would like to have a simple terminal command checking if it's running. If it is, it will shutdown the process. Or if it not running, it will start the server.
To start the server I can enter:
/Applications/NetBeans/glassfish-3.1.1/bin/./asadmin start-domain domain
To stop the server I can enter:
/Applications/NetBeans/glassfish-3.1.1/bin/.asadmin stop-domain domain
I will would like to make a simple Alfred.app script than can start this domain if it's not running, or stop it if it's running.
One way to do this is to note in a file the process ID of the server when it starts, and have another script check to see if that process is running.
For example, script A (to run the server unconditionally):
#!/bin/sh
/Applications/NetBeans/glassfish-3.1.1/bin/./asadmin start-domain domain
# file name is arbitrary
pgrep whateverTheProcessNameIs > ~/.glassfish-server.pid
And in script B:
#!/bin/sh
pid=`pgrep -F ~/.glassfish-server.pid` # file chosen in script A
if [ "x$pid" = "x" ] ; then
# process has died; restart by running script A
/path/to/scriptA
fi
Note that only Mac OS X 10.8 (Mountain Lion) installs pgrep by default; otherwise you'd have to use some other method (like parsing ps output) to see what processes are running.
As far as how to run this check periodically, there are various ways. I'm assuming Alfred will run any script that is executable (chmod +x scriptA scriptB) but I don't know for sure.
I run the wesabe web app locally.
Each time I start it by opening separate shells to start the mysql server, java backend and rails frontend.
My question is, how could you automate this with a shell script or rake task?
I tried just listing the commands sequentially in a shell script (see below) but the later commands never run because each app server creates its own process that never 'returns' (until you quit the server).
I've looked into sub-shells and parallel rake tasks, but that's where I got stuck.
echo 'starting mysql'
mysqld_safe
echo 'starting pfc'
cd ~/wesabe/pfc
rails server -p 3001
echo 'starting brcm'
cd ~/wesabe/brcm-accounts-api
script/server
echo 'ok, go!'
open http://localhost:3001
If you don't mind the output being messed, put a "&" at the end of the line where you start the application to make it run in background.
I have a daemon script written in ruby which responds to commands like daemon start and daemon stop. It's executable with shebang #!/usr/bin/env ruby and it works invoked from terminal. I need to start the daemon on login and stop it on logout.
Background info: KDE, zsh.
I already tried to make two separate shell scripts with daemon start and daemon stop and place them in ~/.kde4/Autostart | ~/.kde4/shutdown. The scripts start.sh and stop.sh are working in terminal, but no luck in autostart or shutdown.
I can't put them in .zshrc respectively .zlogout, because I start many login shells in a work session.
So I am stuck :) Any ideas?
Update: F1 => Help :)
You could try running the program as an autostart app, and then have it watch to see when its parent (probably the session manager) stops running.