• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Start / stop mango from linux shell script

    User help
    4
    13
    8.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • I
      ime
      last edited by

      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 cant 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 
      
      1 Reply Last reply Reply Quote 0
      • M
        mlohbihler
        last edited by

        What do you mean the kill signal doesn't close the database as it should? It does for me.

        Best regards,
        Matthew

        1 Reply Last reply Reply Quote 0
        • JoelHaggarJ
          JoelHaggar
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • I
            ime
            last edited by

            @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.

            1 Reply Last reply Reply Quote 0
            • I
              ime
              last edited by

              @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 im trying this also on raspberry pi (sorry, didt 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.

              1 Reply Last reply Reply Quote 0
              • I
                ime
                last edited by

                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 cant figure out "stop" part. Killall isnt solution.

                1 Reply Last reply Reply Quote 0
                • M
                  mlohbihler
                  last edited by

                  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.

                  Best regards,
                  Matthew

                  1 Reply Last reply Reply Quote 0
                  • I
                    ime
                    last edited by

                    "kill <procId>" seems to work fine. I`ll try in this direction and post here final working script.

                    Thanks.

                    1 Reply Last reply Reply Quote 0
                    • I
                      ime
                      last edited by

                      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.

                      1 Reply Last reply Reply Quote 0
                      • A
                        AlexHK
                        last edited by

                        @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

                        1 Reply Last reply Reply Quote 0
                        • JoelHaggarJ
                          JoelHaggar
                          last edited by

                          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.

                          1 Reply Last reply Reply Quote 0
                          • A
                            AlexHK
                            last edited by

                            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
                            
                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post