{"id":134,"date":"2022-04-23T16:13:28","date_gmt":"2022-04-23T16:13:28","guid":{"rendered":"https:\/\/hb9iiu.com\/?p=134"},"modified":"2022-04-23T16:13:28","modified_gmt":"2022-04-23T16:13:28","slug":"start-a-python-script-in-virtual-environnment-at-boot","status":"publish","type":"post","link":"https:\/\/hb9iiu.synology.me\/wordpress\/index.php\/2022\/04\/23\/start-a-python-script-in-virtual-environnment-at-boot\/","title":{"rendered":"Start a Python Script in Virtual Environnment at Boot"},"content":{"rendered":"\n<p>Tested on Synology<\/p>\n\n\n\n<p>This example is to automatically start at boot the python script created in  <a rel=\"noreferrer noopener\" href=\"https:\/\/hb9iiu.com\/2022\/04\/23\/python-virtual-environments\/?preview_id=105&amp;preview_nonce=9006f54c8d&amp;preview=true\" target=\"_blank\">this post<\/a><\/p>\n\n\n\n<p>Change directory<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/etc\/systemd\/system<\/pre>\n\n\n\n<p>Create the service file<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano flask_test_server.service<\/pre>\n\n\n\n<p>copy &amp; paste below<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[Unit]\nDescription=&lt;project flask_test_server&gt;\n\n[Service]\nUser=root\nWorkingDirectory=\/volume1\/homes\/Daniel\/virtual_env_test\/virtual_python\nExecStart=\/volume1\/homes\/Daniel\/virtual_env_test\/virtual_python\/bin\/python3 flask_test.py\nRestart=always\n\n[Install]\nWantedBy=multi-user.target<\/pre>\n\n\n\n<p>Reload the service files to include the new service<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl daemon-reload<\/pre>\n\n\n\n<p>Start the service<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl start flask_test_server.service<\/pre>\n\n\n\n<p>Check the status of the service<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl status flask_test_server.service<\/pre>\n\n\n\n<p>check also here <a href=\"http:\/\/192.168.0.216:18085\/\" data-type=\"URL\" data-id=\"http:\/\/192.168.0.216:18085\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/192.168.0.216:18085\/<\/a><\/p>\n\n\n\n<p>Enable the service on every reboot<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl enable flask_test_server.service\n<\/pre>\n\n\n\n<p>Et voil\u00e0&#8230;..<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tested on Synology This example is to automatically start at boot the python script created in this post Change directory cd \/etc\/systemd\/system Create the service file sudo nano flask_test_server.service copy &amp; paste below [Unit] Description=&lt;project flask_test_server&gt; [Service] User=root WorkingDirectory=\/volume1\/homes\/Daniel\/virtual_env_test\/virtual_python ExecStart=\/volume1\/homes\/Daniel\/virtual_env_test\/virtual_python\/bin\/python3&#8230; <a href=\"https:\/\/hb9iiu.synology.me\/wordpress\/index.php\/2022\/04\/23\/start-a-python-script-in-virtual-environnment-at-boot\/\" class=\"readmore\">Read more<span class=\"screen-reader-text\">Start a Python Script in Virtual Environnment at Boot<\/span><span class=\"fa fa-angle-double-right\" aria-hidden=\"true\"><\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-134","post","type-post","status-publish","format-standard","hentry","category-linux","content-layout-excerpt-thumb"],"_links":{"self":[{"href":"https:\/\/hb9iiu.synology.me\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hb9iiu.synology.me\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hb9iiu.synology.me\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hb9iiu.synology.me\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hb9iiu.synology.me\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=134"}],"version-history":[{"count":0,"href":"https:\/\/hb9iiu.synology.me\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/134\/revisions"}],"wp:attachment":[{"href":"https:\/\/hb9iiu.synology.me\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hb9iiu.synology.me\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hb9iiu.synology.me\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}