[Unit] \n# \u670d\u52a1\u540d\u79f0\uff0c\u53ef\u81ea\u5b9a\u4e49\nDescription=test.jar \n# \u786e\u4fdd\u8fd9\u4e9b\u670d\u52a1\u7684\u524d\u540e\u987a\u5e8f\nAfter=syslog.target network.target remote-fs.target nss-lookup.target\n \n[Service] \nUser=root\nGroup=root\n# \u542f\u52a8\u547d\u4ee4\nExecStart=\/opt\/jdk1.8.0_161\/bin\/java -server -Xms1024m -Xmx2048m -Dspring.profiles.active=production -jar \/root\/test.jar\nExecReload=\/bin\/kill -s HUP $MAINPID\nExecStop=\/bin\/kill -s QUIT $MAINPID\n \n[Install] \nWantedBy=multi-user.target\n<\/code><\/pre>\n<\/p>\n\u628aservice\u540e\u7f00\u7684\u6587\u4ef6\u7f6e\u4e8e\u6307\u5b9a\u76ee\u5f55\u4e2d\u540e\uff0c\u5c31\u53ef\u4ee5\u7528systemctl\u547d\u4ee4\u6765\u7ba1\u7406\u7a0b\u5e8f\u4e86\uff01<\/p>\n
#\u542f\u52a8test.service\u670d\u52a1<\/p>\n
<\/p>\n
systemctlstarttest.service<\/p>\n
#\u67e5\u770b\u670d\u52a1\u72b6\u6001<\/p>\n
systemctlstatustest.service<\/p>\n
\u7597\u6548\u5982\u4e0b\uff1a<\/p>\n
\u7528\u8fd9\u4e2a\u4e5f\u53ef\u4ee5\u542f\u52a8\u670d\u52a1\uff1a<\/p>\n
serviceteststatus<\/p>\n
\u4f46\u91cd\u542f\u540e\u5c31\u7528\u4e0d\u4e86\u4e86<\/p>\n
\u5728\u4f60\u66f4\u6539\u4e86.service\u6587\u4ef6\u540e\u4f7f\u7528systemctl\u7ba1\u7406\u547d\u4ee4\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u8b66\u544a\u4fe1\u606f\uff1a<\/p>\n
Warning:test.servicechangedondisk.Run'systemctldaemon-reload'toreloadunits.<\/p>\n
\u8fd9\u4e2a\u65f6\u4faf\u5c31\u8981\u91cd\u65b0\u52a0\u8f7dsystemctl\u914d\u7f6e\u4e86\uff0c\u4e4b\u540e\u8fd8\u4f1a\u5e94\u7528\u6700\u65b0\u7684\u914d\u7f6e\u3002<\/p>\n
systemctldaemon-reload<\/p>\n
\u5bf9\u4e8e\u8fd9\u4e9b\u652f\u6301Systemd\u7684\u8f6f\u4ef6linux\u66f4\u6539ip\u5730\u5740\uff0c\u5b89\u88c5\u7684\u65f6\u4faf\uff0c\u4f1a\u624b\u52a8\u5728\/usr\/lib\/systemd\/system\u76ee\u5f55\u6dfb\u52a0\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u3002\u8fd9\u4e2a\u65f6\u4faf\u4f60\u5c31\u53ef\u4ee5\u76f4\u63a5\u7528systemctl\u547d\u4ee4\u6765\u7ba1\u7406\u4e86\u3002<\/p>\n
\u2462\u7528systemctl\u547d\u4ee4\uff0c\u8ba9\u670d\u52a1\u5b9e\u73b0\u5f00\u673a\u542f\u52a8<\/p>\n
\u5230\u7b2c\u2461\u5c0f\u8282\u7684\u6b65\u9aa4\u5c31\u65e9\u5df2\u53ef\u4ee5\u7528systemctl\u7ba1\u7406\u547d\u4ee4\u6765\u7ba1\u7406\u4f60\u81ea\u5df1\u7684\u7a0b\u5e8f\u4e86\uff0c\u82e5\u679c\u4f60\u60f3\u8ba9\u8be5\u7a0b\u5e8f\u5f00\u673a\u542f\u52a8\uff0c\u5c31\u6267\u884c\u4e0b\u8fb9\u7684\u547d\u4ee4\uff08\u4ee5test.service\u4e3a\u4f8b\uff09\u3002<\/p>\n
sudosystemctlenabletest<\/p>\n
\u91cc\u9762\u7684\u547d\u4ee4\u76f8\u5f53\u4e8e\u5728\/etc\/systemd\/system\u76ee\u5f55\u6dfb\u52a0\u4e00\u4e2a\u7b26\u53f7\u94fe\u63a5\uff0c\u6307\u5411\/usr\/lib\/systemd\/system\u4e0a\u9762\u7684test.service\u6587\u4ef6\u3002<\/p>\n
\u8fd9\u662f\u7531\u4e8e\u5f00\u673a\u65f6\uff0cSystemd\u53ea\u6267\u884c\/etc\/systemd\/system\u76ee\u5f55\u4e0a\u9762\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u8fd9\u4e5f\u610f\u5473\u7740\uff0c\u5047\u5982\u628atest.service\u6587\u4ef6\u4e0d\u4f7f\u7528\u7b26\u53f7\u94fe\u63a5\u800c\u662f\u76f4\u63a5\u653e\u5728\/etc\/systemd\/system\u76ee\u5f55\u4e0b\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u5f00\u673a\u542f\u52a8\u3002\u5176\u5b9e\uff0c\u5728\/usr\/lib\/systemd\/system\u82e5\u679c\u6ca1\u6709\u653etest.service\u6587\u4ef6\u5c31\u7528\u4e0d\u4e86systemctl\u547d\u4ee4\u6765\u7ba1\u7406\u7a0b\u5e8f\u4e86\uff01<\/p>\n
\u6ce8\u610f\uff1asystemctlstarttest\u4e5f\u53ef\u4ee5\u7528systemctlstarttest.service<\/p>\n
\n
#\u542f\u52a8test\nsystemctl start test\n#\u505c\u6b62test\nsystemctl stop test\n#\u91cd\u542ftest\nsystemctl restart test\n#\u67e5\u770b\u72b6\u6001test\nsystemctl status test\n#\u5982\u679c\u9700\u8981\u5f00\u673a\u542f\u52a8\nsystemctl enable test\n#\u5982\u679c\u9700\u8981\u53d6\u6d88\u5f00\u673a\u542f\u52a8\nsystemctl disable test\n#\u6740\u8fdb\u7a0b\uff0c\u5411\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u53d1\u51fakill\u4fe1\u53f7\u3002\nsystemctl kill test\n#\u67e5\u770btest\u76f8\u5173\u7684service\u914d\u7f6e\u6587\u4ef6\nsystemctl cat test\n##\u67e5\u770b multi-user.target \u5305\u542b\u7684\u6240\u6709\u670d\u52a1\nsystemctl list-dependencies multi-user.target\n#\u5207\u6362\u5230\u53e6\u4e00\u4e2a target\uff0cshutdown.target \u5c31\u662f\u5173\u673a\u72b6\u6001\nsudo systemctl isolate shutdown.target<\/code><\/pre>\n<\/p>\n\n
service\u7684\u5e38\u7528\u65b9\u5f0f\uff1a\n1.\u683c\u5f0f\uff1aservice \n<\/p>\n\u6253\u5370\u6307\u5b9a\u670d\u52a1\u7684\u547d\u4ee4\u884c\u4f7f\u7528\u5e2e\u52a9\u3002\n2.\u683c\u5f0f\uff1aservice start\n\u542f\u52a8\u6307\u5b9a\u7684\u7cfb\u7edf\u670d\u52a1\n3.\u683c\u5f0f\uff1aservice stop\n\u505c\u6b62\u6307\u5b9a\u7684\u7cfb\u7edf\u670d\u52a1\n4.\u683c\u5f0f\uff1aservice restart\n\u91cd\u65b0\u542f\u52a8\u6307\u5b9a\u7684\u7cfb\u7edf\u670d\u52a1\uff0c\u5373\u5148\u505c\u6b62\uff08stop\uff09\uff0c\u7136\u540e\u518d\u542f\u52a8\uff08start\uff09\u3002\n5.\u683c\u5f0f\uff1achkconfig --list\n\u67e5\u770b\u7cfb\u7edf\u670d\u52a1\u5217\u8868\uff0c\u4ee5\u53ca\u6bcf\u4e2a\u670d\u52a1\u7684\u8fd0\u884c\u7ea7\u522b\u3002\n6.\u683c\u5f0f\uff1achkconfig on\n\u8bbe\u7f6e\u6307\u5b9a\u670d\u52a1\u5f00\u673a\u65f6\u81ea\u52a8\u542f\u52a8\u3002\n7.\u683c\u5f0f\uff1achkconfig off\n\u8bbe\u7f6e\u6307\u5b9a\u670d\u52a1\u5f00\u673a\u65f6\u4e0d\u81ea\u52a8\u542f\u52a8\u3002\n8.\u683c\u5f0f\uff1antsysv\n\u4ee5\u5168\u5c4f\u5e55\u6587\u672c\u754c\u9762\u8bbe\u7f6e\u670d\u52a1\u5f00\u673a\u65f6\u662f\u5426\u81ea\u52a8\u542f\u52a8\u3002\n \n\u6253\u5f00redis\u547d\u4ee4:service redis start\n\u5173\u95edredis\u547d\u4ee4:service redis stop\n\u8bbe\u4e3a\u5f00\u673a\u542f\u52a8:chkconfig redis on<\/code><\/pre>\n<\/p>\n
\u7528sh\u811a\u672c\u8ba9\u670d\u52a1\u5f00\u673a\u81ea\u542f<\/p>\n
1\u3001\u521b\u5efash\u811a\u672c<\/p>\n
\u8bf7\u4f7f\u7528\u4e0b\u8ff0\u65b9\u6cd5\u521b\u5efash\u811a\u672c\uff1aserver.sh\uff08\u811a\u672c\u4eb2\u6d4b\u597d\u7528\uff0c\u4e0d\u7528\u989d\u5916\u914d\u7f6e\u7f16\u8f91\uff09<\/p>\n
\u6ce8\u610f\uff1a\u6587\u4ef6\u90fd\u8981\u8bbe\u7f6e\u4e3a\u53ef\u6267\u884c\u6587\u4ef6:<\/p>\n
\n
sudo chmod 755 run-server.sh<\/code><\/pre>\n<\/p>\n\u2460\u4f7f\u7528notepad++\u8f6f\u4ef6\u8f6c\u6362\u6210unix\u683c\u5f0f\uff0c\u6216\u5219\u7528vim\u7684setff\u547d\u4ee4\u6765\u8f6c\u6362<\/p>\n
notepad++\u5b98\u65b9\u4e0b\u8f7d\u5730\u5740<\/p>\n
\u4f7f\u7528notepad++\u6253\u5f00\u6587\u4ef6---\u7f16\u8f91---\u6587\u6863\u683c\u5f0f\u8f6c\u6362---\u8f6c\u4e3aunix---\u4e0a\u4f20\u81f3linux<\/p>\n
\u2461run-server.sh\u811a\u672c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n
\u5bf9\u4e8e\u4e00\u4e9b\u672a\u63d0\u4f9bservice\u7ba1\u7406\u7684\u7a0b\u5e8f\u6bcf\u6b21\u542f\u52a8\u548c\u5173\u6389\u90fd\u8981\u52a0\u4e0a\u5168\u90e8\u8def\u5f84\uff0c\u60f3\u5230\u53ef\u4ee5\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u542f\u52a8\u548c\u5173\u6389\u63a7\u5236\u7684\u6587\u4ef6\u3002<\/p>\n
\u4e0b\u8fb9\u4ee5scrapy\u542f\u52a8server\u4e3a\u4f8b\uff1a<\/p>\n
\n
#\u7aef\u53e3\u53f7\uff0c\u6839\u636e\u6b64\u7aef\u53e3\u53f7\u786e\u5b9aPID\nPORT=6800\n#\u542f\u52a8\u547d\u4ee4\u6240\u5728\u76ee\u5f55\nHOME='\/home\/jmscra\/scrapy\/'\n \n#\u67e5\u8be2\u51fa\u76d1\u542c\u4e86PORT\u7aef\u53e3TCP\u534f\u8bae\u7684\u7a0b\u5e8f\npid=`netstat -lnopt | grep :$PORT | awk '\/python\/{gsub(\/\/python\/,\"\",$7);print $7;}'`\n \n \nstart(){\n if [ -n \"$pid\" ]; then\n<\/p>\n echo \"server already start,pid:$pid\"\n return 0\n fi\n \n #\u8fdb\u5165\u547d\u4ee4\u6240\u5728\u76ee\u5f55\n cd $HOME\n nohup scrapy server & #\u542f\u52a8scrpayd\u670d\u52a1\u5668 \u628a\u65e5\u5fd7\u8f93\u51fa\u5230HOME\u76ee\u5f55\u7684nohup.out\u6587\u4ef6\u4e2d \n echo \"start at port:$PORT\"\n}\n \nstop(){\n if [ -z \"$pid\" ]; then\n echo \"not find program on port:$PORT\"\n return 0\n fi\n \n #\u7ed3\u675f\u7a0b\u5e8f\uff0c\u4f7f\u7528\u8baf\u53f72\uff0c\u5982\u679c\u4e0d\u884c\u53ef\u4ee5\u5c1d\u8bd5\u8baf\u53f79\u5f3a\u5236\u7ed3\u675f\n kill -2 $pid \n echo \"kill program use signal 2,pid:$pid\"\n}\n \nstatus(){\n if [ -z \"$pid\" ]; then\n echo \"not find program on port:$PORT\"\n else\n echo \"program is running,pid:$pid\"\n fi\n}\n \ncase $1 in\n start)\n start\n ;;\n stop)\n stop\n ;;\n status)\n status\n ;;\n *)\n
<\/p>\n echo \"Usage: {start|stop|status}\"\n ;;\nesac\n \nexit 0<\/code><\/pre>\n<\/p>\n
\u6d4b\u8bd5\u4f7f\u7528\u65f6\u53ef\u4ee5<\/p>\n
\/path\/run.shstart\u542f\u52a8<\/p>\n
\/path\/run.shstop\u505c\u6b62<\/p>\n
\/path\/run.shstatus\u67e5\u770b\u8fd0\u884c\u7a0b\u5e8f\u7684pid<\/p>\n
\u628a\u524d\u9762\u8fd9\u4e2a\u811a\u672c\u8bbe\u7f6e\u4e3a\u5f00\u673a\u81ea\u542f\u7684\u670d\u52a1,\u53ef\u4ee5\u7528\u524d\u9762\u7684systemd\u5de5\u5177\uff0c\u628ash\u6587\u4ef6\u653e\u5728service\u6587\u4ef6\u4e2d\u5373\u53ef\u3002\u4e0b\u8fb9\u7528\u53e6\u4e00\u79cd\u65b9\u5f0f\u81ea\u542f\u3002<\/p>\n
\u7cfb\u7edfrc.local\u6587\u4ef6\u5b9e\u73b0\u81ea\u542f<\/p>\n
\u7f16\u8f91\u7cfb\u7edfrc.local\u6587\u4ef6\uff0c\u8ba9\u811a\u672c\u52a0\u5165\u7cfb\u7edf\u5f00\u673a\u542f\u52a8<\/p>\n
\u5728\u91cc\u9762\u7684\u7b2c\u4e00\u6b65\u5c31\u53ef\u4ee5\u4f7f\u7528\u811a\u672c\u6765\u7ba1\u7406\u7a0b\u5e8f\u4e86\uff0c\u63a5\u51fa\u6765\u662f\u8ba9\u811a\u672c\u52a0\u5165\u5230\u7cfb\u7edf\u7684\u5f00\u673a\u542f\u52a8<\/p>\n
\u8bb0\u5f55\u5f53\u524dserver.sh\u811a\u672c\u7684\u8def\u5f84,\u7f16\u8f91\/etc\/rc.d\/rc.local\u3002\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n
cd\/etc\/rc.d<\/p>\n
virc.local<\/p>\n
\n
#!\/bin\/bash\n# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES\n#\n# It is highly advisable to create own systemd services or udev rules\n# to run scripts during boot instead of using this file.\n#\n# In contrast to previous versions due to parallel execution during boot\n# this script will NOT be run after all other services.\n#\n# Please note that you must run 'chmod +x \/etc\/rc.d\/rc.local' to ensure\n# that this script will be executed during boot.\n \n#\u5c31\u662f\u8bf4rc.local\u7684\u7a0b\u5e8f\u5df2\u7ecf\u542f\u52a8\u4e86, \u9632\u6b62\u91cd\u590d\u8fd0\u884c\ntouch \/var\/lock\/subsys\/local\n \n#\u811a\u672c\u7684\u7edd\u5bf9\u8def\u5f84\n\/root\/run-server.sh\n <\/code><\/pre>\n<\/p>\n\u7cfb\u7edf\u91cd\u542f\uff0c\u67e5\u770b\u7597\u6548<\/p>\n
\n
sudo reboot<\/code><\/pre>\n<\/p>\n\u67e5\u770b\u7a0b\u5e8f\uff1a<\/p>\n
\n
ps -ef | grep scrapy<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"\u5229\u7528systemd\u5de5\u5177\u7ba1\u7406\u7a0b\u5e8f\uff0c\u5b9e\u73b0\u670d\u52a1\u5f00\u673a\u81ea\u542f\u52a8\u2462\u7528systemctl\u547d\u4ee4\uff0c\u8ba9\u670d\u52a1\u5b9e\u73b0\u5f00\u673a\u542f\u52a8\u628a\u4e0a\u9762\u8fd9\u4e2a\u811a\u672c\u8bbe\u7f6e\u4e3a\u5f00\u673a\u81ea\u542f\u7684\u670d\u52a1,\u53ef\u4ee5\u7528\u4e0a\u9762\u7684systemd\u5de5\u5177\uff0c\u628ash\u6587\u4ef6\u653e\u5230service\u6587\u4ef6\u4e2d\u5373\u53ef\u3002\u5728\u4e0a\u9762\u7684\u7b2c\u4e00\u6b65\u5c31\u53ef\u4ee5\u4f7f\u7528\u811a\u672c\u6765\u7ba1\u7406\u7a0b\u5e8f\u4e86\uff0c\u63a5\u4e0b\u6765\u662f\u8ba9\u811a\u672c\u52a0\u5165\u5230\u7cfb\u7edf\u7684\u5f00\u673a\u542f\u52a8<\/p>\n","protected":false},"author":1,"featured_media":295148,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[5128,5000,4156,5129,5130],"class_list":["post-295147","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-nml-2","tag-slj","tag-htyx","tag-hlgdxh","tag-bzsrsccdx"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/295147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=295147"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/295147\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/295148"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=295147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=295147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=295147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}