Issue Starting up ColdFusion 2018 on Solaris 11.3 on non-root account - bash

I have a Solaris system with 3 users ( root, cfruntime , cfdev)
After a successful installation of ColdFusion 2018, the owner of the coldfusion2018 installation is cfruntime.
As cfdev I try starting ColdFusion using the following command
sudo /disktwo/coldfusion2018/cfusion/bin/coldfusion start
This however doesnt appear to start coldfusion normally, but also doesn't generate any abonormal error/log
Looking at the startup script /disktwo/coldfusion2018/cfusion/bin/coldfusion. The folllowing lines actually starts ColdFusion
CFSTART='su $RUNTIME_USER -c "LD_LIBRARY_PATH=$LD_LIBRARY_PATH;
export LD_LIBRARY_PATH;
cd $CF_DIR/bin;
$JAVA_EXECUTABLE -classpath $CLASSPATH $JVM_ARGS
com.adobe.coldfusion.bootstrap.Bootstrap -start &"'
eval $CFSTART > /dev/null
An interesting observation I made was that if I removed the & at the end of the CFSTART, ColdFusion would start normally (although I need to put it in the background crtl-z , bg)
The ColdFusion process doesn't appear to be persistent after exiting the startup script if started as (cfdev/cfruntime) , but starts normally if the script is run as root.
Any thoughts?

Adding a nohup before the $JAVA_EXECUTABLE command and sending the output to >/dev/null 2>&1 did the trick for me
CFSTART='su $RUNTIME_USER -c "LD_LIBRARY_PATH=$LD_LIBRARY_PATH;
export LD_LIBRARY_PATH;
cd $CF_DIR/bin;
nohup $JAVA_EXECUTABLE -classpath $CLASSPATH $JVM_ARGS
com.adobe.coldfusion.bootstrap.Bootstrap -start > /dev/null 2>&1 &"'
I found that it appears that switching to the runtime user su $RUNTIME_USER and starting the process in the background caused all jobs started by the shell to close once the startup script completed (sending a hangup signal (SIGHUP) to all jobs started by that terminal) .
The nohup prevents the $JAVA_EXECUTABLE from closing when it recives the hangup signal (SIGHUP)

Related

How to run Bash Script on startup and keep monitoring the results on the terminal

Due to some issues I wont elaborate here to not waste time, I made a bash script which will ping google every 10 minutes and if there is a response it will keep the loop running and if not then the PC will restart. After a lot of hurdle I have been able to make the script and also make it start on bootup. However the issue is that i want to see the results on the terminal, meaning I want to keep monitoring it but the terminal does not open on bootup. But it does open if I run it as ./net.sh.
The script is running on startup, that much I know because I use another script to open an application and it works flawlessly.
My system information
NAME="Linux Mint"
VERSION="18.3 (Sylvia)"
ID=linuxmint
ID_LIKE=ubuntu
PRETTY_NAME="Linux Mint 18.3"
VERSION_ID="18.3"
HOME_URL="http://www.linuxmint.com/"
SUPPORT_URL="http://forums.linuxmint.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/linuxmint/"
VERSION_CODENAME=sylvia
UBUNTU_CODENAME=xenial
The contents of my net.sh bash script are
#! /bin/bash
xfce4-terminal &
sleep 30
while true
do
ping -c1 google.com
if [ $? == 0 ]; then
echo "Ping Sucessful. The Device will Continue Operating"
sleep 600
else
systemctl reboot
fi
done
I have put the scripts in /usr/bin and inserted the scripts for startup at boot in /etc/rc.local
So I did some further research and with help from reddit I realized that the reason I couldnt get it to show on terminal was because the script was starting on bootup but I needed it to start after user login. So I added the script on startup application (which can be found searching on start menu if thats whats it called). But it was still giving issues so I divided the script in two parts.
I put the net.sh script on startup and directed that script to open my main script which i named net_loop.sh
This is how the net.sh script looks
#! /bin/bash
sleep 20
xfce4-terminal -e usr/bin/net_loop.sh
And the net_loop.sh
#! /bin/bash
while true
do
ping -c1 google.com
if [ $? == 0 ]; then
echo "Ping Sucessful. The Device will Continue Operating"
sleep 600
else
systemctl reboot
fi
done
The results are the results of the net_loop.sh script are open in another terminal.
Note: I used help from this thread
If minute interval is usable why not use "cron" to start your?
$> crontab –e
or
$> sudo crontab –e

Start a process in background, do a task, then kill the process in the background

I have a script that looks like this:
pushd .
nohup java -jar test/selenium-server.jar > /dev/null 2>&1 &
cd web/code/protected/tests/
phpunit functional/
popd
The selenium servers needs to be running for the tests, however after the phpunit command finishes I'd like to kill the selenium-server that was running.
How can I do this?
You can probably save the PID of the process in a variable, then use the kill command to kill it.
pushd .
nohup java -jar test/selenium-server.jar > /dev/null 2>&1 &
serverPID=$!
cd web/code/protected/tests/
phpunit functional/
kill $serverPID
popd
I haven't tested it myself, I'd like to write it on a comment, but not enough reputation yet :)
When the script is excecuted a new shell instance is created. Which means that the jobs in the new script would not list any jobs running in the parent shell.
Since the selenium-server server is the only background process that is created in the new script it can be killed using
#The first job
kill %1
Or
#The last job Same as the first one
kill %-
As long as you don't launch any other process in the background - which you don't - you can use $! directly:
pushd .
nohup java -jar test/selenium-server.jar > /dev/null 2>&1 &
cd web/code/protected/tests/
phpunit functional/
kill $!
popd

Run SSH command nohup then exit from server via Jenkins

So I've tried googling and reading a few questions on here as well as elsewhere and I can't seem to find an answer.
I'm using Jenkins and executing a shell script to scp a .jar file to a server and then sshing in, running the build, and then exiting out of the server. However, I cannot get out of that server for the life of me. This is what I'm running, minus the sensitive information:
ssh root#x.x.x.x 'killall -9 java; nohup java -jar /root/project.jar -prod &; exit'
I've tried doing && exit, exit;, but none of it will get me out of the server and jenkins just spins for ever. So the Jenkins build never actually finishes.
Any help would be sweet! I appreciate it.
So I just took off the exit and ran a ssh -f root#x.x.x.x before the command and it worked. The -f just runs the ssh command in the background so Jenkins isn't sitting around waiting.
Usual way of starting a command and sending it to background is nohup command &
Try this. This is working for me. Read the source for more information.
nohup some-background-task &> /dev/null # No space between & and > !
Example :
ssh root#x.x.x.x 'killall -9 java; nohup java -jar /root/project.jar -prod &> /dev/null'
no need exit keyword
source : https://blog.jakubholy.net/2015/02/17/fix-shell-script-run-via-ssh-hanging-jenkins/

Shell Script Start a Server and return

I have a shell script that starts a server. I actually ssh into my server and run the shell script. As soon as it starts, it logs everything to the console and the console does not return. The problem starts when I close my Machine, the ssh connection is disconnected and the server that I started is shutdown. I guess I need to start the server and return from the shell. Here is what I have so far:
#!/bin/bash
java -Xmx1G -Dhttp.port=8080 -Dconfig.file=MyProject/conf/application.conf -cp ".:MyProject/lib/*" play.core.server.NettyServer .
exit 0
Any suggestions on how to return after calling this shell script?
After ssh to the server Just backgrounding your script (./myscript &) will not daemonize it. You must disconnect stdin, stdout, and stderr, and make it ignore the hangup signal (SIGHUP).
nohup ./myscript 0<&- &>/dev/null &
will do the job. Or, to capture all output:
nohup ./myscript 0<&- &> my.admin.log.file &
To avoid script termination on ssh session close use nohup (No hangup) with output redirection to a log file:
nohup bash /path/to/startScript.sh > script.log 2>&1 &
You can redirect stdout and stderr to files, background and disown the process (or nohup it) and then exit the script.
However, the correct way to do this is to use some kind of process manager daemon like upstart.

Why is this command in the bash script not running in the background?

I have a bash script that includes the following lines:
.
.
if [ -z "$(pgrep mplayer)" ]; then
/usr/bin/mplayer -slave -input file=/home/administrator/files/mplayer-control.pipe http:/www.musicserveraddress.com/ &
fi
.
.
Other things to execute
.
exit
what happens is that mplayer connects to the streamingserver and start playing the stream. However, the script never moves on. I added an ampersand to move this process to the background so that the script should continue to run and then exit itself (keeping the audio stream playing).
How should I do to achieve that?
Thanks in advance/J
Edit: It runs as planned when I run the script from the command line, but it is intended to be run as a cron job (and the pgrep is intended to start mplayer only if it has crashed since last cron job). When run as a cron job, nothing happens...
Try with a nohup at the beginning of the command :
nohup /usr/bin/mplayer -slave -input file=/home/administrator/files/mplayer-control.pipe http:/www.musicserveraddress.com/ &
The command you've used works perfectly fine for me. The only thing that can confuse people is that you don't get the bash prompt when the script finishes, but it's actually there, try pressing Enter.
As you want the player to be controlled via a pipe and be in the background, I'd recommend to redirect standard streams from the console as well and send all the output to a logfile:
(
exec </dev/null
exec >/dev/null
exec 2>/dev/null
umask 0
cd /
exec setsid mplayer -slave -idle -input /home/user/control.pipe http://server.com > /var/log/mplayer.log 2>&1
) &
You may want to use setsid as well. That worked for me.

Resources