0

I'm the only software developer in my company. I deployed a .NET Core 2.2 web application on Ubuntu 18.04 with several utilities for my coworkers, and to keep the application running, I installed the application as a service. All of this is working fine.

I'm currently working on automating my deployment and update workflow. Currently, the entire process is automated via PowerShell and bash scripts (developing on Windows 10) except restarting the application service after deployment, because this requires root access to achieve as far as I know.

I understand that it is possible to enable the use of sudo without a password. This is not what I'm trying to achieve at the moment (although this is an acceptable fallback since the application is hosted on our intranet and the application is trivial in nature). Given service name my-app.service, I would like to execute

systemctl restart my-app

rather than

sudo systemctl restart my-app

to enable adding the restart command to my PowerShell script on the development machine. The service is trivial in nature, and nothing that it does requires root access. The app is hosted in my home directory and all permissions are set correctly. The service simply runs the app.dll using the dotnet executable. I currently access the deployment machine via SSH and restart the service manually, but I would prefer not to do this if at all possible.

This is the service file. (I prefer hosting websites from a user's home directory, so that part is correct for my configuration - as I said, everything works the way it is expected to work, just not the way I want.)

[Unit]
Description=Some inhouse tool for --Company Name--

[Service]
WorkingDirectory=/home/username/website.com
ExecStart=/usr/bin/dotnet /home/username/website.com/app.dll
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=--Company Name--app
User=username
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]

WantedBy=multi-user.target

I have tried searching ServerFault, AskUbuntu, Unix&Linux, and the web at large, to no avail. I've looked through literally hundreds of questions (over 200 at last count) that may have been related, but most of those questions either weren't related, or wanted to circumvent entering a password on sudo instead of circumventing sudo altogether. If the answer did slip through the cracks, I apologize in advance.

  • Unfortunately you decided to use a Debian-based distribution, so your options are very limited. Linux does have a nice solution for this, but Debian chose not to use it (and so Ubuntu also doesn't have it). See the linked Q&A for the one option available to you if you remain on Ubuntu, and the options available if you switch distributions. – Michael Hampton Jul 25 '19 at 21:32
  • I appreciate the link. Sorry I missed that question. It looks like one of those solutions will work for my situation. – Christian Speegle Jul 25 '19 at 21:59
  • For anyone who visits this question looking for an answer, [this answer](https://serverfault.com/a/841150/533133) on the duplicated question is the solution that worked for me. Implementing the service as a user service was simple to set up and works like a charm. – Christian Speegle Aug 01 '19 at 19:57

0 Answers0