{"id":628,"date":"2012-03-30T17:16:14","date_gmt":"2012-03-30T16:16:14","guid":{"rendered":"http:\/\/www.xenonique.co.uk\/blog\/?p=628"},"modified":"2012-03-30T17:16:14","modified_gmt":"2012-03-30T16:16:14","slug":"ubuntu-activemq-initialisation-scripts","status":"publish","type":"post","link":"https:\/\/www.xenonique.co.uk\/blog\/2012\/03\/30\/ubuntu-activemq-initialisation-scripts\/","title":{"rendered":"Ubuntu ActiveMQ Initialisation Scripts"},"content":{"rendered":"<p>Recently, I have been working with <a title=\"Ubuntu\" href=\"https:\/\/www.ubuntu.org\/\">Ubuntu<\/a> in a <strong><a title=\"Oracle Virtual Box\" href=\"https:\/\/www.virtualbox.org\/\">Virtual Box VM<\/a><\/strong> and setting up <strong><a href=\"https:\/\/activemq.apache.org\/\">ActiveMQ<\/a><\/strong> for testing. I wanted to create a VM with an already running ActiveMQ as a service, whenever I started it. In order to do this, I set up ActiveMQ as a Linux intialisation service. I installed ActiveMQ first by following the very helpful<a title=\"Getting Starting with Apache ApacheMQ\" href=\"https:\/\/activemq.apache.org\/getting-started.html#GettingStarted-StartingActiveMQ\"> blog entry here<\/a>, which was a little out of date. It only explained how to create an <a title=\"Apache MQ Sys V Unix Service\" href=\"https:\/\/activemq.apache.org\/unix-service.html\">ActiveMQ Init.d if you have Sys V Linux\/Unix<\/a> machine. So I went about customising the information for a Ubuntu machine, and the results are now here. Here are my scripts, the first is located at <span style=\"color: #008000;\"><code>\/home\/activemq\/activemqstart.sh<\/code><\/span>. This script launches the service and is \u00a0owned by the Linux user <span style=\"color: #008000;\"><code>activemq<\/code><\/span>.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;\/pre&gt;\r\n#!\/bin\/bash # Start ActiveMQ if [ ! -f ${HOME}\/activemq.env ]; then echo &quot;Cannot read activemq.env&quot; 1&gt;&amp;2; exit 99 fi . ${HOME}\/activemq.env ${ACTIVEMQ_HOME}\/bin\/activemq start # fini\r\n&lt;pre&gt;<\/pre>\n<p>Here is the script file <span style=\"color: #008000;\"><code>\/home\/activemq\/activemqstatus.sh<\/code><\/span>, which shows the administrator the status of the service.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;\/pre&gt;\r\n#!\/bin\/bash # Probe ActiveMQ if [ ! -f ${HOME}\/activemq.env ]; then echo &quot;Cannot read activemq.env&quot; 1&gt;&amp;2; exit 99 fi . ${HOME}\/activemq.env ${ACTIVEMQ_HOME}\/bin\/activemq status # fini\r\n&lt;pre&gt;<\/pre>\n<p>Here is the script file <span style=\"color: #008000;\"><code>\/home\/activemq\/activemqstop.sh<\/code><\/span>, which allows the administrator to halt the service.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;\/pre&gt;\r\n#!\/bin\/bash # Stop ActiveMQ if [ ! -f ${HOME}\/activemq.env ]; then echo &quot;Cannot read activemq.env&quot; 1&gt;&amp;2; exit 99 fi . ${HOME}\/activemq.env ${ACTIVEMQ_HOME}\/bin\/activemq stop # fini\r\n&lt;pre&gt;<\/pre>\n<p>Here is the environmental set-up script <span style=\"color: #008000;\"><code>\/home\/activemq\/activemq.env<\/code><\/span>. Of course, if you wanted to, you could put this configuration elsewhere like in a .bashrc script. For my purposes, I wanted to refactor out the location of both components.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;\/pre&gt;\r\n: ${JAVA_HOME:=\/usr\/lib\/jvm\/java-6-sun-1.6.0.31} : ${JDK_HOME:=\/usr\/lib\/jvm\/java-6-sun-1.6.0.31} : ${ACTIVEMQ_HOME:=\/opt\/apache-activemq}\r\n&lt;pre&gt;<\/pre>\n<p>Here is a version of ActiveMQ control script in<span style=\"color: #008000;\"> <code>\/etc\/init.d\/activemq<\/code><\/span>, which owned by the superuser root.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n#\r\n# activemq       Starts ActiveMQ.\r\n#\r\n#\r\n### BEGIN INIT INFO\r\n# Provides:          activemq\r\n# Required-Start:    $local_fs $remote_fs $network $syslog\r\n# Required-Stop:     $local_fs $remote_fs $network $syslog\r\n# Default-Start:     1 2 3 4 5\r\n# Default-Stop:      0 1 2 6\r\n# Short-Description: Start daemon at boot time\r\n# Description:       Enable service provided by Apache Active MQ.\r\n### END INIT INFO\r\n\r\n# Source function library.\r\n## . \/etc\/init.d\/functions\r\n\r\n# Load the VERBOSE setting and other rcS variables\r\n. \/lib\/init\/vars.sh\r\n\r\n# Define LSB log_* functions.\r\n# Depend on lsb-base (&gt;= 3.0-6) to ensure that this file is present.\r\n. \/lib\/lsb\/init-functions\r\n\r\n[ -f \/home\/activemq\/activemqstart.sh ] || exit 0\r\n[ -f \/home\/activemq\/activemqstop.sh ] || exit 0\r\n[ -f \/home\/activemq\/activemqstatus.sh ] || exit 0\r\n\r\nRETVAL=0\r\n\r\numask 077\r\n\r\nstart() {\r\n       echo -n $&quot;Starting ActiveMQ: &quot;\r\n       su -c \/home\/activemq\/activemqstart.sh activemq\r\n       echo\r\n       return $RETVAL\r\n}\r\nstop() {\r\n       echo -n $&quot;Shutting down ActiveMQ: &quot;\r\n       su -c \/home\/activemq\/activemqstop.sh activemq\r\n       echo\r\n       return $RETVAL\r\n}\r\nstatus() {\r\n       echo -n $&quot;Probing status of ActiveMQ: &quot;\r\n       su -c \/home\/activemq\/activemqstatus.sh activemq\r\n       echo\r\n       return $RETVAL\r\n}\r\nrestart() {\r\n       stop\r\n       start\r\n}\r\ncase &quot;$1&quot; in\r\n start)\r\n       start\r\n       ;;\r\n stop)\r\n       stop\r\n       ;;\r\n restart|reload)\r\n       restart\r\n       ;;\r\n status|probe)\r\n        status\r\n        ;;\r\n *)\r\n       echo $&quot;Usage: $0 {start|stop|restart|status|probe}&quot;\r\n       exit 1\r\nesac\r\n\r\nexit $?\r\n# Fini\r\n<\/pre>\n<p>I will assume that you are familiar with creating Linux users and setting file owner and group permissions. Finally, I installed the new service with this following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo update-rc.d activemq start 20 1 2 3 4 5 . stop 80 0 1 2 6 .\r\n<\/pre>\n<p>This command installs the service for single-user, multi-user, network configured and display configured run-levels. HTH. Al Coda. \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I have been working with Ubuntu in a Virtual Box VM and setting up ActiveMQ for testing. I wanted to create a VM with an already running ActiveMQ as a service, whenever I started it. In order to do this, I set up ActiveMQ as a Linux intialisation service. I installed ActiveMQ first by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[80,72,81,138,82],"tags":[],"_links":{"self":[{"href":"https:\/\/www.xenonique.co.uk\/blog\/wp-json\/wp\/v2\/posts\/628"}],"collection":[{"href":"https:\/\/www.xenonique.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xenonique.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xenonique.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xenonique.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=628"}],"version-history":[{"count":14,"href":"https:\/\/www.xenonique.co.uk\/blog\/wp-json\/wp\/v2\/posts\/628\/revisions"}],"predecessor-version":[{"id":642,"href":"https:\/\/www.xenonique.co.uk\/blog\/wp-json\/wp\/v2\/posts\/628\/revisions\/642"}],"wp:attachment":[{"href":"https:\/\/www.xenonique.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xenonique.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xenonique.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}