[{"data":1,"prerenderedAt":184},["ShallowReactive",2],{"blog-\u002Fblog\u002F2023\u002F05\u002Fdevice-agent-as-a-service":3},{"id":4,"title":5,"body":6,"description":12,"extension":171,"meta":172,"navigation":179,"path":180,"seo":181,"stem":182,"__hash__":183},"blog\u002Fblog\u002F2023\u002F05\u002Fdevice-agent-as-a-service.md","Running the FlowFuse Device Agent as a service on a Raspberry Pi",{"type":7,"value":8,"toc":158},"minimark",[9,13,16,21,29,33,38,45,50,54,57,85,96,99,103,106,111,114,119,123,126,131,134,139,142,147,151],[10,11,12],"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.",[10,14,15],{},"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.",[17,18,20],"h2",{"id":19},"why-run-the-device-agent-as-a-service","Why run the device agent as a service?",[10,22,23,24,28],{},"The standard process for running FlowFuse's device agent is to start it on the\ncommand line using the command ",[25,26,27],"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.",[17,30,32],{"id":31},"set-up-steps","Set up steps",[34,35,37],"h3",{"id":36},"create-the-service-file","Create the Service File",[10,39,40,41,44],{},"The first step is creating the systemd unit file for your service. You can start by creating a new file in the\n",[25,42,43],{},"\u002Fetc\u002Fsystemd\u002Fsystem"," directory with a .service file extension:",[10,46,47],{},[25,48,49],{},"sudo nano \u002Fetc\u002Fsystemd\u002Fsystem\u002Fflowforge-device-agent.service",[34,51,53],{"id":52},"define-the-service","Define the Service",[10,55,56],{},"In the service file, you'll need to define the following parameters:",[58,59,60,67,73,79],"ul",{},[61,62,63,66],"li",{},[25,64,65],{},"Description",": A brief description of what the service does.",[61,68,69,72],{},[25,70,71],{},"ExecStart",": The command(s) to execute to start the service.",[61,74,75,78],{},[25,76,77],{},"User and Group",": The user and group that the service runs as.",[61,80,81,84],{},[25,82,83],{},"Type",": Whether the service is a simple or a forking type.",[10,86,87,88,95],{},"We've created the content you'll need for this file and shared it via ",[89,90,94],"a",{"href":91,"rel":92},"https:\u002F\u002Fgithub.com\u002FFlowFuse\u002Fdevice-agent\u002Fblob\u002Fmain\u002Fservice\u002Fflowfuse-device.service",[93],"nofollow","this GitHub page",".",[10,97,98],{},"Copy the code from that page into the nano window you created in step 1, then save and exit out of nano.",[34,100,102],{"id":101},"starting-the-service-on-boot-optional","Starting the service on boot (optional)",[10,104,105],{},"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:",[10,107,108],{},[25,109,110],{},"sudo systemctl enable flowforge-device-agent.service",[10,112,113],{},"To disable the service, run the command:",[10,115,116],{},[25,117,118],{},"sudo systemctl disable flowforge-device-agent.service",[34,120,122],{"id":121},"using-your-new-service","Using your new service",[10,124,125],{},"You can now start your service with the start command:",[10,127,128],{},[25,129,130],{},"sudo systemctl start flowforge-device-agent",[10,132,133],{},"You can check the current status with the status command:",[10,135,136],{},[25,137,138],{},"sudo systemctl status flowforge-device-agent",[10,140,141],{},"Finally, if you need to stop your agent you can do so with the command:",[10,143,144],{},[25,145,146],{},"sudo systemctl stop flowforge-device-agent",[17,148,150],{"id":149},"further-reading","Further reading",[10,152,153,154,157],{},"If you'd like to learn about using services via the systemctl command you can access\nthe help text by running ",[25,155,156],{},"systemctl -h"," from your Pi terminal.",{"title":159,"searchDepth":160,"depth":160,"links":161},"",2,[162,163,170],{"id":19,"depth":160,"text":20},{"id":31,"depth":160,"text":32,"children":164},[165,167,168,169],{"id":36,"depth":166,"text":37},3,{"id":52,"depth":166,"text":53},{"id":101,"depth":166,"text":102},{"id":121,"depth":166,"text":122},{"id":149,"depth":160,"text":150},"md",{"navTitle":5,"excerpt":173},{"type":7,"value":174},[175,177],[10,176,12],{},[10,178,15],{},true,"\u002Fblog\u002F2023\u002F05\u002Fdevice-agent-as-a-service",{"title":5,"description":12},"blog\u002F2023\u002F05\u002Fdevice-agent-as-a-service","eOAHLF_Z8qlGggwIxF__UzSbBW1zZA757jdHH7Ljph0",1780070550513]