[{"data":1,"prerenderedAt":199},["ShallowReactive",2],{"blog-\u002Fblog\u002F2023\u002F05\u002Fdevice-agent-as-a-service":3,"blog-all-for-related":198},{"id":4,"title":5,"authors":6,"body":8,"cta":174,"date":175,"description":176,"extension":177,"image":178,"lastUpdated":174,"meta":179,"navigation":186,"path":187,"seo":188,"sitemap":189,"stem":190,"subtitle":191,"tags":192,"tldr":174,"video":174,"__hash__":197},"blog\u002Fblog\u002F2023\u002F05\u002Fdevice-agent-as-a-service.md","Running the FlowFuse Device Agent as a service on a Raspberry Pi",[7],"rob-marcer",{"type":9,"value":10,"toc":160},"minimark",[11,15,18,23,31,35,40,47,52,56,59,87,98,101,105,108,113,116,121,125,128,133,136,141,144,149,153],[12,13,14],"p",{},"FlowFuse's device agent allows you to manage and run your Node-RED instances on\nyour own hardware such as a Raspberry Pi. This can be very useful where an\napplication you've written needs to run flows with direct access to hardware sensors.",[12,16,17],{},"In this article I'm going to explain the steps to configure our device agent to run as a service in Raspbian OS,\nor any other OS that uses systemd.",[19,20,22],"h2",{"id":21},"why-run-the-device-agent-as-a-service","Why run the device agent as a service?",[12,24,25,26,30],{},"The standard process for running FlowFuse's device agent is to start it on the\ncommand line using the command ",[27,28,29],"code",{},"flowforge-device-agent",". This works fine for testing\nbut for long-term installations it's useful to run the device agent as a service.\nOnce running as a service, the device agent will continue to run even if your\ndevice is restarted or your SSH connection to your Pi fails.",[19,32,34],{"id":33},"set-up-steps","Set up steps",[36,37,39],"h3",{"id":38},"create-the-service-file","Create the Service File",[12,41,42,43,46],{},"The first step is creating the systemd unit file for your service. You can start by creating a new file in the\n",[27,44,45],{},"\u002Fetc\u002Fsystemd\u002Fsystem"," directory with a .service file extension:",[12,48,49],{},[27,50,51],{},"sudo nano \u002Fetc\u002Fsystemd\u002Fsystem\u002Fflowforge-device-agent.service",[36,53,55],{"id":54},"define-the-service","Define the Service",[12,57,58],{},"In the service file, you'll need to define the following parameters:",[60,61,62,69,75,81],"ul",{},[63,64,65,68],"li",{},[27,66,67],{},"Description",": A brief description of what the service does.",[63,70,71,74],{},[27,72,73],{},"ExecStart",": The command(s) to execute to start the service.",[63,76,77,80],{},[27,78,79],{},"User and Group",": The user and group that the service runs as.",[63,82,83,86],{},[27,84,85],{},"Type",": Whether the service is a simple or a forking type.",[12,88,89,90,97],{},"We've created the content you'll need for this file and shared it via ",[91,92,96],"a",{"href":93,"rel":94},"https:\u002F\u002Fgithub.com\u002FFlowFuse\u002Fdevice-agent\u002Fblob\u002Fmain\u002Fservice\u002Fflowfuse-device.service",[95],"nofollow","this GitHub page",".",[12,99,100],{},"Copy the code from that page into the nano window you created in step 1, then save and exit out of nano.",[36,102,104],{"id":103},"starting-the-service-on-boot-optional","Starting the service on boot (optional)",[12,106,107],{},"If you want Node-RED to run when the Pi is turned on, or re-booted, you can enable the service to autostart by running the command:",[12,109,110],{},[27,111,112],{},"sudo systemctl enable flowforge-device-agent.service",[12,114,115],{},"To disable the service, run the command:",[12,117,118],{},[27,119,120],{},"sudo systemctl disable flowforge-device-agent.service",[36,122,124],{"id":123},"using-your-new-service","Using your new service",[12,126,127],{},"You can now start your service with the start command:",[12,129,130],{},[27,131,132],{},"sudo systemctl start flowforge-device-agent",[12,134,135],{},"You can check the current status with the status command:",[12,137,138],{},[27,139,140],{},"sudo systemctl status flowforge-device-agent",[12,142,143],{},"Finally, if you need to stop your agent you can do so with the command:",[12,145,146],{},[27,147,148],{},"sudo systemctl stop flowforge-device-agent",[19,150,152],{"id":151},"further-reading","Further reading",[12,154,155,156,159],{},"If you'd like to learn about using services via the systemctl command you can access\nthe help text by running ",[27,157,158],{},"systemctl -h"," from your Pi terminal.",{"title":161,"searchDepth":162,"depth":162,"links":163},"",4,[164,166,173],{"id":21,"depth":165,"text":22},2,{"id":33,"depth":165,"text":34,"children":167},[168,170,171,172],{"id":38,"depth":169,"text":39},3,{"id":54,"depth":169,"text":55},{"id":103,"depth":169,"text":104},{"id":123,"depth":169,"text":124},{"id":151,"depth":165,"text":152},null,"2023-05-02","Learn how to run the FlowFuse Device Agent as a service on your Raspberry Pi with this step-by-step guide. Ensure uninterrupted operation even after device restarts.","md","\u002Fblog\u002F2023\u002F05\u002Fimages\u002Fagent-on-pi.png",{"excerpt":180},{"type":9,"value":181},[182,184],[12,183,14],{},[12,185,17],{},true,"\u002Fblog\u002F2023\u002F05\u002Fdevice-agent-as-a-service",{"title":5,"description":176},{"loc":187},"blog\u002F2023\u002F05\u002Fdevice-agent-as-a-service","Step by step guide to run the device agent as a service",[193,194,195,196],"posts","flowfuse","how-to","raspberry pi","bUI55E-Vzo5k4uP7RMNIrAboyM3RtrgHmLc25cN5mOA",[],1785528685381]