Start / stop mango from linux shell script
-
Can someone help me with advice how to stop mango from /etc/init.d shell script.
I want to start mango automatically after machine boots and this works ok, but for shutdown i tried with sending killall signal which is not good as it doesnt close database as it should so mango can
t be started again.So the question is how should i modify stop case in next script so that mango finishes the same way when closed with ctrl+c from terminal window:
#! /bin/sh # /etc/init.d/mango case "$1" in start) echo "Starting mango" /home/user/mango/ma-start.sh ;; stop) echo "Stopping mango" killall mango ;; *) echo "Usage: /etc/init.d/mango {start|stop}" exit 1 ;; esac exit 0
-
What do you mean the kill signal doesn't close the database as it should? It does for me.
-
Attached is a linux service that works on Ubuntu. I put it in the ext/init/ dir You'll have to edit the path to the ma-start.sh file but then you can run sudo service mango start and sudo service mango stop from the terminal.
Let me know if this works for you?
Joel.
Attachment: download link
-
@mlohbihler said:
What do you mean the kill signal doesn't close the database as it should? It does for me.
I mean then when i close mango with command "/etc/init.d/mango stop" from another terminal window i cannot run it again because it says the another instance of db is already running. It doesn`t terminate mango as does ctrc+c inside terminal from which mango is started, but rather forcefully shuts it down leaving database open.
-
@JoelHaggar said:
Attached is a linux service that works on Ubuntu. I put it in the ext/init/ dir You'll have to edit the path to the ma-start.sh file but then you can run sudo service mango start and sudo service mango stop from the terminal.
Let me know if this works for you?
Joel.
Thanks, this works on ubuntu. I already have similar conf file on ubuntu machine, but i
m trying this also on raspberry pi (sorry, did
t mention at the beginning) which has some issues with upstart configuration files, and i was hoping getting mango as a service through init.d kind of script. Do you have any idea about this?
Also starting on boot with this script as i wrote in first post is not good because mango should run after all other service - with this script i locked myself without login prompt and also ssh deamon didn`t started, so i had to correct files on SD card from another linux box. -
Ok i changed script a bit so that it works for automatic startup at boot. I added $ALL $sshd in required-start and "&" char at the end of calling ma-start.sh. Now i can get to login prompt from keyboard and also connect over ssh to the system. Also in etc/rc.local file i added these two llines for getting serial port to work correctly with mango (thanks to Cyberdog):
sudo ln -s /dev/ttyAMA0 /dev/ttyS0 sudo chown root:dialout /dev/ttyS0
now my /etc/init.d/mango script looks like this:
#! /bin/sh # /etc/init.d/mango ### BEGIN INIT INFO # Provides: mango # Required-Start: $ALL $sshd $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Description: script to start / stop mango ### END INIT INFO case "$1" in start) echo "Starting mango" /home/pi/mango/ma-start.sh & ;; stop) echo "Stopping mango" killall mango ;; *) echo "Usage: /etc/init.d/mango {start|stop}" exit 1 ;; esac exit 0
Still can
t figure out "stop" part. Killall isn
t solution. -
It sounds like the killall on the platform is sending a -9 signal or something, instead of a HUP. Perhaps there is a flag you can add to ensure that HUP is being sent.
Otherwise, what happens if you kill manually with "kill <procId>" instead? Does that close the database properly? If so, there are examples of scripts around that will store the process id on startup and then use it for shutdown.
-
"kill <procId>" seems to work fine. I`ll try in this direction and post here final working script.
Thanks.
-
Actually the "missing link" was catching pid of java, not mango, so simple "kill
pidof java
" instead "killall mango" inside stop part of script seems to work just fine. -
@JoelHaggar said:
Attached is a linux service that works on Ubuntu. I put it in the ext/init/ dir You'll have to edit the path to the ma-start.sh file but then you can run sudo service mango start and sudo service mango stop from the terminal.
Let me know if this works for you?
Joel.
Thanks for posting this. I have purchased a license and everything is fine (license file in mango directory). But when I use sudo service mango start to fire up Mango, it says the core module is running on a free license. I have added some code to the script to change into the mango directory before the exec command, but it didn't make a difference. Any ideas?
Ubuntu Server 12.04
Alex
-
Hi Alex,
We are working on this issue. The path that Mango is installed in is used in the GUID and when Mango is started by a service that path looks different and Mango gets a different Guid. If you email me your new GUID I'll generate a new license file for you that will work when running as a service.
Joel.
-
I have received the new license file thanks.
If anyone needs to see the log when Mango starts as a service under Ubuntu Linux (12.04) it's at /var/log/upstart/mango.log
Look at the log continuously:
sudo tail -f /var/log/upstart/mango.log