Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 6136

Restart a systemctl service not from root (Ubuntu 22.04) without password

$
0
0

I'm doing a CI/CD pipeline and my plan is when everything is uploaded onto the server to restart a couple of systemctl services:

systemctl restart market-service-app.servicesystemctl restart market-service-api.service

I have a spacial prepared user that is supposed to execute these restarts. The action is gonna be triggered from a github actions build agent. The appropriate SSH key is already prepared into github secrets and public part is added into authorized_keys, everything works except one part: my user (github_actions) cant perform the restart without root password! I tried a million of tutorials, I added my github_actions user into the sudo group, configured sudoers:

github_actions@mycomputer123$ systemctl restart market-service-api.service==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units === Authentication is required to restart 'market-service-api.service'. Authenticating as: ,,, (github_actions)Password:                                                                                                                                                                   

Are there any CI/CD guru here? Can you show me what is wrong? I just want to be able to run

systemctl restart market-service-app.servicesystemctl restart market-service-api.service

using ssh from github_actions user.

Here is the text of the service files:

[Unit]Description=Market Service Frontend App[Service]#PermissionsStartOnly=trueUser=github_actionsGroup=github_actionsType=forkingWorkingDirectory=/var/market-service/app/serverExecStart=/home/github_actions/.nvm/versions/node/v20.12.2/bin/node server.mjsRestart=always# Restart service after 10 seconds if the dotnet service crashes:RestartSec=10KillSignal=SIGINTSyslogIdentifier=market-service-frontend-app[Install]WantedBy=multi-user.target
[Unit]Description=Market Service WebAPI                                                                                                                                                                                                                                                                                  [Service]WorkingDirectory=/var/market-service/api ExecStart=/usr/bin/dotnet ./MarketService.WebApi.dll Restart=always # Restart service after 10 seconds if the dotnet service crashes:RestartSec=10 KillSignal=SIGINT SyslogIdentifier=market-service-api Environment=ASPNETCORE_ENVIRONMENT=ProductionEnvironment=DOTNET_NOLOGO=true                                                                                                                                                                                                                                                                                      [Install]WantedBy=multi-user.target

and my sudoers update:

github_actions ALL=(ALL) /bin/systemctl restart market-service-app.service, /bin/systemctl restart market-service-api.service

Viewing all articles
Browse latest Browse all 6136

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>