Score:1

Running a command line .net application on boot, as a user, without needing login

my flag

I have a dotnet console application that when executed will run a loop and await a keypress. On certain keypresses it will perform an action (via api calls etc..)

I have a raspberry pi running ubuntu server 22.10 (64 bit) on the pi.

I want to run a command like this:

dotnet /home/myuser/src/prototypes/devops-control/Client/bin/Debug/net6.0/devops-control.dll "loop"

when the pi boots up so that I can use a simple macro pad as a keyboard, and send the command to the application.

The application is basically

if arg[0] == 'loop' 
{
    while(true)
    {
        var key = Console.ReadKey().KeyChar;
        PerformAction(key)
    }
}

I have dotnet installed, and setup in the path of my user (if I ssh in and run the command everything works as expected)

But I would just like this to happen when I boot the pi up so I can leave it headless with just a macro pad plugged in.

Ideally it would simply boot up, auto login as the user without me putting in a password, and then run the command which would run the application waiting for keypresses. Meaning I can ssh into the pi and pull new version of the code etc.. and just have it all in one place.

Score:1
us flag

You need to run the process as a systemd service.

It's a bit of a long process and here is one nice article that explains the steps (and provides some background).

Here's another explanation that may help from SO.

And, finally, one that shows how to set up a .NET app to run that way.

And, here is a great resource from DigitalOcean that shows how to manage services.

Mark McGookin avatar
my flag
You are a star. Thanks!
Mark McGookin avatar
my flag
This does sort of answer my question, so I have marked it as such. @raddevus thanks for the info. Alas, these "background workers" don't capture keyboard input via Console.Read as I had hoped (which makes sense, as they run in the background without a console window open) Do you know what would be the best way to capture input from a systemd service?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.