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.