I would start a script on boot for Raspberry with raspbian. I found and followed well known method to start script on boot.
But, where can I find the messages of my script? I'm not sure that the script started. For example, a simple script:
#!/bin/bash
case "$1" in
start)
echo "Start script"
;;
....
esac
exit 0
Where can I find the "Start script" message?
Thank you!
Roberto
Related
how to make sure first command finishes and then only execute second command in shell script
#!/bin/sh
echo "Stopping application"
#command to stop application
echo "Starting application"
#command to start application
In above code, I wanted to make sure that command to stop application is finished properly and then only start the application.
How to handle this.
Please note in my case if application is already stopped then command to stop application takes some random time to complete i.e. 20sec, 30 sec .
So adding sleep is not proper way.
Main moto behind script is to restart application.
Considering fact that if application is allready stopped it doesnt work properly.
If application is running then the script works perfect.
You can use the command return code and a condition to do this.
#!/bin/sh
echo "Stopping application"
#command to stop application
rc=$?
# if the stop command was executed successfuly
if [ $rc == 0 ]; then
echo "Starting application"
#command to start application
else
echo "ERROR - return code: $rc"
fi
There are 'exit codes', try this:
ls
...
echo $?
0
than:
ls non_existing_file
ls: cannot access 'non_existing_file': No such file or directory
echo $?
2
This command echo $? prints exit code of previous command, if it's 0 than it's OK, all non 0 codes means some kind of error which is not OK.
I need to start my Wildfly AS through .sh script after system boot (Linux-Debian). So I created my own script which should do it in init.d:
#! /bin/sh
# /etc/init.d/starter
case "$1" in
start)
echo "Starting"
nohup /home/xxx/wildfly-9.0.1.Final/bin/standalone.sh &
;;
stop)
echo "Stopping"
/home/xxx/wildfly-9.0.1.Final/bin/jboss-cli.sh --connect command=:shutdown
;;
*)
echo "Usage: /etc/init.d/starter {start|stop}"
exit 1
;;
esac
exit 0
This works if i use it on my own: /etc/init.d/starter start.
Then I used command to create symlinks: update-rc.d starter defaults. Symlinks are created just as expected, however after reboot command the script is not executed.
Does someone knows what prevents my script from being executed after boot? Thank you for all your advices.
Problem was that i did not know that initial script must set its own $PATH and other variables. I found it out when I saw java:not found in /var/log/daemon. At the end I found that wildfly has its own scirpt init-debian.sh. I used it and it works.
I'm a novice with linux or any command line, but I've managed to gain root access to my Buffalo Terastation (TS-HTGL/R5) and install noip & mediatomb.
The problem I have is that I can't get noip2 to automatically start, but I figured out what to do for mediatomb (using a guide). I have the following script in /opt/etc/init.d/S90noip2 but I get the error bad interpreter: no such file or directory
#! /bin/sh
case "$1" in
start)
echo "Starting noip2."
/opt/bin/noip2
;;
stop)
echo -n "Shutting down noip2."
killall noip2
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
I would try the following things:
Remove space between #! and /bin/bash in the first line. You should have: #!/bin/bash
Make the file is executable: chmod +x /opt/etc/init.d/S90noip2
Check that /opt/bin/noip2 actually exists.
Try running /opt/bin/noip2 by hand to see if it works.
If none of the above steps helped, post your results here, so we can figure out further steps.
If your problem is solved, accept this answer and click up vote button. :)
PS: And don't forget the bounty. :D
I programmed a JavaFX application which runs on a "Raspberry Pi" (a small ARM based Linux Computer). The OS on the "Pi" is "Raspbian" (a Debian Linux for Raspberry Pi). I installed JDK8 on Raspbian to run graphic JavaFX Application without X-Server. This all works fine :) I can start the Application by entering the following command:
/opt/jdk1.8.0/bin/java -cp /home/pi/sqljdbc4.jar:/home/pi/Leitwarte.jar leitwarte.Leitwarte
When the application starts it takes full control over mouse an keyboard, so there is no way back into console, but this doesent maters because it is just a monitoring system an i am able to shut the mashine down over ssh.
I now want to start the application directly after booting, so that there is no need for entering username ,passwort and starting the application.
The mashine does nothing else just running the app (of course there runs a ftp, ssh deamon for making updating the app posible)
Please tell me step by step, because i dont work with Linux for a long time.
Thank you very much.
CMD
cd /etc/init.d
sudo nano leitwarte
Enter the following
#! /bin/sh
# /etc/init.d/leitwarte
touch /var/lock/leitwarte
case "$1" in
start)
echo "Starting Leitwarte ... "
/opt/jdk1.8.0/bin/java -cp /home/pi/sqljdbc4.jar:/home/pi/Leitwarte.jar leitwarte.Leitwarte > /dev/null &
;;
stop)
echo "Killing Leitwarte ..."
killall java
;;
*)
echo "Usage: /etc/init.d/leitwarte {start|stop}"
exit 1
;;
esac
exit 0
then
chmod 755 leitwarte
update-rc.d leitwarte defaults
DONE
I solved this problem
When the application starts it takes full control over mouse an
keyboard, so there is no way back into console
by adding quotes ("") and by giving -Djavafx.platform=gtk for DEFAULT_JVM_OPTS.
For example in my case I replaced this code:
DEFAULT_JVM_OPTS=-XX:+UseG1GC -Dmode=prod_w_updates
to this:
DEFAULT_JVM_OPTS="-XX:+UseG1GC -Dmode=prod_w_updates -Djavafx.platform=gtk"
Hope, it will help
I am using an Amazon Linux AMI and doing some custom modifications(added an axis2server, etc) on it and saving it as a new AMI. Now what I want to do is when the AMI boots up, start up axis2server(ie.axis2server should automatically start when the instance boots up). For that I used a init script like below and ran the following command:
chkconfig --add axisservice
But when I launch a new instance from my image, the axis2server is not getting started.
I just only need to execute the script /home/ec2-user/axis2-1.6.1/bin/axis2server.sh at startup. Am I missing anything here?
#! /bin/sh
# Basic support for IRIX style chkconfig
###
# chkconfig: 235 98 55
# description: Manages the services you are controlling with the chkconfig command
###
case "$1" in
start)
echo -n "Starting axisservice"
touch ~/temp.txt
cd /home/ec2-user/axis2-1.6.1/bin
./axis2server.sh &
echo "."
;;
stop)
echo -n "Stopping axisservice"
echo "."
;;
*)
echo "Usage: /sbin/service axisservice {start|stop}"
exit 1
esac
exit 0
I went through https://help.ubuntu.com/community/CloudInit as well and it provides a mechanism called User-Data Scripts, where a user can execute a script when launching the script.
$ euca-run-instances --key mykey --user-data-file myscript.sh ami-axxxx
This is a command line option and what I want is something like when I launch the instance through the UI, the script should be started.Therefore, I think the above option can not be used in my case. Please correct me if I am wrong.
Thanks,
H.
I bet the environment is not set(up correctly). This means that I am guessing that your shell script tries to start another program and it's not to be found.
So at first, I'd adjust the start part of your script (current):
echo -n "Starting axisservice"
touch ~/temp.txt
cd /home/ec2-user/axis2-1.6.1/bin
./axis2server.sh &
echo "."
Edited:
echo -n "Starting axisservice"
touch ~/temp.txt
cd /home/ec2-user/axis2-1.6.1/bin
./axis2server.sh
RETVAL=$?
[ $RETVAL -eq 0 ] && echo Success
[ $RETVAL -ne 0 ] && echo Failure
echo "."
So what did I do?
removed & so script waits for your shell script (axis2server.sh) to complete
checked the return status ($?) of your shell script
Further debugging:
Add set -x to your scripts to enable tracing and log both stderr and stdout.
Questions:
Are you are aware that stop (in your service script) doesn't do anything?
touch ~/temp.txt is that supposed to create /root/temp.txt? (I'm guessing root runs this script.)
If none of my suggestions work, can you share axis2server.sh and paste stderr and stdout?