{"id":4409,"date":"2014-11-24T18:25:21","date_gmt":"2014-11-24T10:25:21","guid":{"rendered":"http:\/\/lttt.blog.ustc.edu.cn\/?p=4409"},"modified":"2014-11-24T18:25:21","modified_gmt":"2014-11-24T10:25:21","slug":"autorun-mcmyadmin-at-rebootstart-linuxubuntu","status":"publish","type":"post","link":"https:\/\/lttt.vanabel.cn\/?p=4409","title":{"rendered":"AutoRun McMyAdmin at reboot\/start (Linux\/Ubuntu)"},"content":{"rendered":"<p>1. Login as root, create a file as<br \/>\n<code>vim \/etc\/init.d\/McMyAdmin.sh<\/code><br \/>\n2. Copy and paste the following content into it<\/p>\n<pre lang=\"sh\">\n#!\/bin\/sh\n# \/etc\/init.d\/McMyAdmin\n# version 0.0.1 2014-11-24\n\n### BEGIN INIT INFO\n# Provides:          McMyAdmin\n# Required-Start:    $local_fs $remote_fs screen-cleanup $syslog\n# Required-Stop:     $local_fs $remote_fs $syslog\n# Default-Start:     2 3 4 5\n# Default-Stop:      0 1 6\n# Short-Description: Start McMyAdmin at boot\n# Description:       Start McMyAdmin at boot.\n### END INIT INFO\n#Settings\nUSERNAME='mcserver'\nSERVICE='McMyAdmin'\nMCAPATH=\"\/home\/$USERNAME\/McMyAdmin\"\nINVOCATION=\"cd $MCAPATH && screen -dmS $SERVICE .\/MCMA2_Linux_x86_64\"\n\nME=\"$(whoami)\"\nas_user() {\n        if [ \"$ME\" = \"$USERNAME\" ] ; then\n                bash -c \"$1\"\n        else\n                su - \"$USERNAME\"  -c \"$1\"\n        fi\n}\n\n\ncase \"$1\" in\n        start)\n                if pgrep -u $USERNAME -f $SERVICE > \/dev\/null\n                then\n                        echo \"McMyAdmin is already started on screen McMyAdmin\"\n                else\n                        echo \"Starting $SERVICE ...\"\n                        cd $MCAPATH\n                        as_user \"$INVOCATION\"\n                        sleep 7\n                        if pgrep -u $USERNAME -f $SERVICE > \/dev\/null\n                        then\n                                echo \"McMyAdmin started on screen $SERVICE\"\n                        else\n                                echo \"Error! Could not start $SERVICE\"\n                        fi\n                fi\n                ;;\n        stop)\n                if pgrep -u $USERNAME -f $SERVICE > \/dev\/null\n                then\n                        echo \"Stopping $SERVICE...\"\n                        as_user \"screen -X -S $SERVICE kill\"\n                        sleep 7\n                else\n                        echo \"$SERVICE was not running.\"\n                fi\n                if pgrep -u $USERNAME -f $SERVICE -a > \/dev\/null\n                then\n                        echo \"Error! $SERVICE could not be stopped.\"\n                else\n                        echo \"$SERVICE is stopped.\"\n                fi\n                ;;\n        *)\n                echo \"Usage: \/etc\/init.d\/McMyAdmin_autostart {start|stop}\"\n                exit 1\n                ;;\nesac\nexit 0\n<\/pre>\n<p>Pleae note that you need to adjust the USERNAME and MCAPATH.<br \/>\n3. <code>:wq<\/code> to save and quit<br \/>\n4. Change the mode of the file<br \/>\n<code>chmod +x \/etc\/init.d\/McMyAdmin.sh<\/code><br \/>\n5. create soft link to startup<br \/>\n<code>update-rc.d McMyAdmin.sh defaults 99<\/code><br \/>\nNote that you can remove it by<br \/>\n<code>update-rc.d -f McMyAdmin.sh remove<\/code><br \/>\n6. reboot to test.<br \/>\n7. If it is not work, try to run as root, with the following command<br \/>\n<code>\/etc\/init.d\/McMyAdmin start<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Login as root, create a file as vim \/ &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/lttt.vanabel.cn\/?p=4409\"> <span class=\"screen-reader-text\">AutoRun McMyAdmin at reboot\/start (Linux\/Ubuntu)<\/span> \u9605\u8bfb\u66f4\u591a &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-4409","post","type-post","status-publish","format-standard","hentry","category-net"],"_links":{"self":[{"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=\/wp\/v2\/posts\/4409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4409"}],"version-history":[{"count":0,"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=\/wp\/v2\/posts\/4409\/revisions"}],"wp:attachment":[{"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}