{"id":1990,"date":"2017-10-29T16:49:54","date_gmt":"2017-10-29T07:49:54","guid":{"rendered":"http:\/\/www.rgm79sf.site\/wordpress\/?p=1990"},"modified":"2018-04-26T09:55:21","modified_gmt":"2018-04-26T00:55:21","slug":"raspberry-pi-%e3%81%a7systemd%e3%81%ae%e3%81%8a%e5%8b%89%e5%bc%b7","status":"publish","type":"post","link":"https:\/\/www.rgm79sf.site\/?p=1990","title":{"rendered":"Raspberry Pi \u3067systemd\u306e\u304a\u52c9\u5f37"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u30b8\u30e0\u3067\u3059\u3002<\/p>\n<p>\u672c\u65e5\u4e8c\u5ea6\u76ee\u306e\u66f4\u65b0\u3067\u3059\u3002<\/p>\n<p>\u5148\u307b\u3069<a href=\"https:\/\/www.rgm79sf.site\/wordpress\/?p=1981\">discord bot\u8a2d\u7f6e\u306e\u8a18\u4e8b<\/a>\u3092\u516c\u958b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u306e\u5f8csystemd\u306b\u767b\u9332\u3057\u3066\u81ea\u52d5\u8d77\u52d5\u307e\u3067\u884c\u304f\u306e\u306b\u5c11\u3057\u30cf\u30de\u3063\u305f\u306e\u3067\u3053\u308c\u3082\u30e1\u30e2\u3068\u3057\u3066\u7f6e\u3044\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>\u305d\u3082\u305d\u3082systemd\u3068\u306f\u4f55\u305e\u3084\u3002<\/p>\n<p>systemd \u306f sysvinit \u306e\u5f8c\u7d99\u3002<\/p>\n<p>\u96fb\u6e90\u6295\u5165\u5f8c\u306b\u81ea\u52d5\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u52d5\u304b\u3057\u305f\u3044\u6642\u3068\u304b\u306b\u4f7f\u3046\u3002<\/p>\n<p>\u4f7f\u3046\u306b\u306f\/etc\/systemd\/system\/\u3000\u306b\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308a\u30b3\u30de\u30f3\u30c9\u3067\u767b\u9332\u3057\u3066\u3042\u3052\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u4eca\u56de\u306fdiscord bot\u3092\u81ea\u52d5\u8d77\u52d5\u3059\u308b\u3064\u3082\u308a\u3067\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u5fdc\u7528\u3059\u308c\u3070\u81ea\u4f5c\u30b9\u30af\u30ea\u30d7\u30c8\u3068\u304b\u30de\u30a4\u30af\u30e9\u30b5\u30fc\u30d0\u30fc\u3068\u304b\u306a\u3093\u3067\u3082\u81ea\u52d5\u5316\u3067\u304d\u307e\u3059\u3002\uff08\u306a\u3093\u3067\u3082\u306f\u8a00\u3044\u904e\u304e\uff1f\uff09<\/p>\n<p>&nbsp;<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<p>\u307e\u305a\u524d\u63d0<\/p>\n<p>\u30fb\u8d77\u52d5\u3057\u305f\u3044run.py\u306f\u3000~\/MusicBot\/\u3000\u306b\u5c45\u308b\u3002<\/p>\n<p>\u30fbscreen \u3092\u4f7f\u3063\u3066\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u751f\u6210\u3057\u3064\u3064\u8d77\u52d5\u3057\u305f\u3044\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u3053\u306e\u5834\u5408\u7528\u610f\u3059\u308b\u3082\u306e\u306f<\/p>\n<p>\u30fb\u8d77\u52d5\u7528\u30b9\u30af\u30ea\u30d7\u30c8<\/p>\n<p>\u30fbsystemd\u7528\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb<\/p>\n<p>\u306e\u4e8c\u3064\u3002<\/p>\n<p>\u3067\u306f\u3001\u305d\u308c\u305e\u308c\u6e96\u5099\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u8d77\u52d5\u7528\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3059\u304c\u3001\u3053\u308c\u306e\u5834\u6240\u306f\u304a\u597d\u307f\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306frun.py\u3068\u540c\u3058~\/MusicBot\/\u3000\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u3053\u306b<\/p>\n<pre>#!\/bin\/bash\r\n\r\ncd ~\/MusicBot\r\n\r\nscreen -d -m python3.5 run.py<\/pre>\n<p>\u3068\u3044\u3046\u7c21\u5358\u306a\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u66f8\u3044\u3066run.sh\u3068\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>\u66f8\u3044\u305f\u3089chmod \u3067\u5b9f\u884c\u6a29\u3092\u4ed8\u3051\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<pre>$sudo chmod 755 run.sh<\/pre>\n<p>\u3053\u308c\u3067\u4e00\u3064\u3081\u306e\u6e96\u5099\u306f\u7d42\u308f\u308a\u3002<\/p>\n<p>\u6b21\u306fsystemd\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u306f\/etc\/systemd\/system\/\u306b\u66f8\u304f\u3068\u3044\u3046\u6c7a\u307e\u308a\u304c\u3042\u308b\u306e\u3067<\/p>\n<pre>$cd \/etc\/systemd\/system<\/pre>\n<p>\u3067\u79fb\u52d5\u3057\u3066<\/p>\n<p>bot.service\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<pre>$sudo vim bot.service<\/pre>\n<p>bot.service \u4e2d\u8eab<\/p>\n<pre>[Unit]\r\nDescription = music bot\r\nAfter=network.target\r\n\r\n[Service]\r\nUser = pi\r\nType=forking\r\nExecStart =\/home\/pi\/MusicBot\/run.sh\r\nRestart = no\r\n\r\n[Install]\r\nWantedBy = multi-user.target<\/pre>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067\u4e2d\u8eab\u3092\u66f8\u3044\u3066\u304a\u304f\u3002\u4e2d\u8eab\u306b\u95a2\u3057\u3066\u306f\u4ee5\u4e0b\u3092\u53c2\u8003\u306b\u66f8\u304d\u307e\u3057\u305f\u3002<\/p>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" title=\"Systemd\u5165\u9580(4) - service\u30bf\u30a4\u30d7Unit\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb - \u3081\u3082\u3081\u3082\" src=\"https:\/\/hatenablog-parts.com\/embed?url=http%3A%2F%2Fenakai00.hatenablog.com%2Fentry%2F20130917%2F1379374797#?secret=4gIZSAFZbE\" data-secret=\"4gIZSAFZbE\" scrolling=\"no\" frameborder=\"0\"><\/iframe><\/p>\n<p>\u4e2d\u8eab\u3092\u66f8\u304d\u7d42\u3048\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u623b\u3063\u3066\u304d\u305f\u3089<\/p>\n<pre>$sudo systemctl enable bot.service<\/pre>\n<p>\u3067\u767b\u9332\u3057\u3066\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u6b62\u3081\u305f\u3044\u5834\u5408\u306fenable\u3092disabled\u306b\u5909\u3048\u3066\u6253\u3066\u3070\u6b62\u307e\u308a\u307e\u3059\u3002<\/p>\n<p>\u3042\u3068\u306freboot\u3068\u304b\u6253\u3063\u3066\u307f\u3066\u3001\u81ea\u52d5\u3067bot\u304c\u8d77\u52d5\u3059\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3067\u304d\u308c\u3070\u5b8c\u6210\u3067\u3059\u3002<\/p>\n<p>systemd \u3068\u3063\u3064\u304d\u306b\u304f\u3044\u3051\u3069\u4fbf\u5229\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u3044\u308d\u3044\u308d\u306a\u3068\u3053\u308d\u3067\u4f7f\u308f\u308c\u3066\u3044\u308b\u3088\u3046\u306a\u306e\u3067\u3001\u77e5\u3063\u3066\u304a\u3044\u3066\u640d\u306f\u306a\u3044\u304b\u3082\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u30b8\u30e0\u3067\u3059\u3002 \u672c\u65e5\u4e8c\u5ea6\u76ee\u306e\u66f4\u65b0\u3067\u3059\u3002 \u5148\u307b\u3069discord&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[30,3],"class_list":["post-1990","post","type-post","status-publish","format-standard","hentry","category-7","tag-raspberrypi","tag-ubuntu"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=\/wp\/v2\/posts\/1990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1990"}],"version-history":[{"count":0,"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=\/wp\/v2\/posts\/1990\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}