debian init.d script not running after reboot - linux

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.

Related

How to convert sysvinit script to systemd on Manjaro

First, please don't consider this post as a systemd review or critic, but only and simply as a request for help.
Since I've not been able to find a solution to this problem with the systemd documentation, I've this question not solved for almost a year and a half that never ever received any answer.
So, here is the context:
I've a program (/opt/myprog) that can be sarted as a deamon service at boot time.
When using previous Debian, LMDE, Mint or Ubuntu OSes, I used SysVinit with the following script (myprog.sh within the /etc/init.d folder):
MYPROG_PATH=/opt/myprog_64
NAME="myprog"
START="-d"
STOP="-k"
TEST=""
VERSION="-v"
SCRIPTNAME=/etc/init.d/$NAME
STARTMESG="\nStarting $NAME in deamon mode.\n"
UPMESG="\$NAME is running.\n"
DOWNMESG="\$NAME is not running!\n"
TESTMESG="\nStarting NAME in client mode.\nHit Ctrl+C (or close the terminal) to stop mprog.\n"
STATUS=`pidof $NAME`
# Exit if myprog is not installed
[ -x "$MYPROG_PATH/$NAME" ] || exit 0
case "$1" in
start)
sleep 3
echo $STARTMESG
cd $MYPROG_PATH
./$NAME $START
;;
stop)
cd $MYPROG_PATH
./$NAME $STOP
;;
status)
if [ "$STATUS" > 0 ] ; then
echo $UPMESG
else
echo $DOWNMESG
fi
;;
restart)
cd $MYPROG_PATH
./$NAME $STOP
echo $STARTMESG
./$NAME $START
;;
version)
cd $MYPROG_PATH
./$NAME $VERSION
;;
test)
cd $MYPROG_PATH
echo $TESTMESG
./$NAME
;;
*)
echo "Usage: $SCRIPTNAME {start|status|restart|stop|version|test}" >&2
exit 3
;;
esac
:
Now, since it's obvious that systemd will be widely adopted to replace SysVinit including with future Debian, Mint and Ubuntu distros as it's with CentOS, Fedroa or Ach and Manjaro, I've tried to adapt my sysVinit script to systemd with the following script that works but is too limited (myprog.service):
Description=myprog
ConditionFileExecutable=/opt/myprog_64
After=NetworkManager.service
[Service]
Type=oneshot
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ExecStart=/opt/myprog -d
ExecStop=/opt/myprog -k
ExecRestart=/opt/myprog-k : /opt/myprog -d
TimeoutSec=0
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
However, as systemd is advertised as compatible and more flexible than SysVinit, could anyone show me how to add the three following equivalent switches (status, test and version) that I have defined in the myprog.sh sysVinit script without responding with the classic and inelegant answer: "man is your friend" ?
/opt/myprog status to display the myprog status (i.e. running or not)
/opt/myprog test to start myprog not as a deamon
/opt/myprog version to display the release of myprog
Thank you in advance fo your time and help.
systemd does not support custom implementation of arguments to systemctl.
So systemctl status myprog will show the results based the execution of Exec* settings.
systemctl show myprog uses the Description so you can use a version in your description if desired.
If you wan't to run your program not as a daemon, then you can start it outside of systemd.

Script start on boot: where to find messages

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

"can't cd" within init.d when started as service

I have a very simple script running in init.d to start a node server using forever. It has been working perfectly until recently and i cannot find what can have changed. I am on Debian 7, have not done any update recently.
This is my script (copied from somewhere, and kept simple simple, it is for tests )
#!/bin/sh
#/etc/init.d/nodeup
. /lib/lsb/init-functions
export PATH=$PATH:/usr/local/bin
export NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules
. /home/pat/env
cd /var/www/mydir
FOREVER_ROOT=/var/log/forever/mydir
export FOREVER_ROOT
case "$1" in
start)
exec forever start -m 10 -o $FOREVER_ROOT/output.log -e $FOREVER_ROOT/error.log ./bin/www ./
;;
stop)
exec forever stop ./bin/www
;;
*)
echo "Usage: service nodeup {start|stop}"
exit 1
;;
esac
exit 0
The problem is that when I run (with start or stop, same effect)
sudo service nodeup start
I get
/etc/init.d/nodeup: 12: cd: can't cd to /var/www/mydir
if I run the script with sudo /etc/init.d/nodeup start
it runs perfectly, no problem.
I cannot understand what is going on, or what could have changed on my machine.
Any idea of what I should check that might give now this behaviour ? or what to change in my script so it works again ?
Thanks for any help
I changed the shell of the script from sh to bash
It seems to have rendered the script more stable

Autostart noip2 on Buffallo NAS (Optware)

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

Adding a service startup script for Amazon linux AMI

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?

Resources