{"id":6139,"date":"2022-04-26T16:47:00","date_gmt":"2022-04-26T15:47:00","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=6139"},"modified":"2025-07-31T12:40:16","modified_gmt":"2025-07-31T11:40:16","slug":"dotnet-systemd-service-file-as-user","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/dotnet-systemd-service-file-as-user\/","title":{"rendered":"Dotnet systemd service file as user"},"content":{"rendered":"\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"sh\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\"># create or copy the service file in \/etc\/systemd\/user\nvim \/etc\/systemd\/user\/$servicename.service\n\n# create service user (only when you have not one already)\nuseradd -m -U $username\n\n\n\n# list service configuration\nsystemctl cat $servicename\n\n# log in as the user\nsu - $username -s \/bin\/bash\nsystemctl --user daemon-reload\n\n# test run in the current console (foreground)\nsystemctl --user console $servicename\n\n# you're able to user the commands below WITHOUT sudo\/root!\nsystemctl --user start $servicename\nsystemctl --user stop $servicename\nsystemctl --user status $servicename\n# run at user-login\nsystemctl --user enable $servicename\n\n# run as root: start user at boot\/leave at logout\nloginctl enable-linger $username\n<\/pre><\/div>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"sh\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">[Unit]                                                             \nDescription=$servicename\n[Service]                                                          \nExecStart=\/usr\/bin\/dotnet \/home\/$username\/$servicename\/Build\/WebApi.dll\nRestart=always                                                     \nRestartSec=10                                                      \nKillSignal=SIGINT                                                  \nSyslogIdentifier=$servicename                                 \n#User=(NOT AVAILABLE IN USER MODE)\n#Group=(NOT AVAILABLE IN USER MODE)                                               \nEnvironment=ASPNETCORE_ENVIRONMENT=production                      \nEnvironment=DOTNET_CLI_TELEMETRY_OPTOUT=1                          \nEnvironment=DOTNET_PRINT_TELEMETRY_MESSAGE=false                   \nWorkingDirectory=\/home\/$username\/$servicename\/Build\/                   \n                                                                   \n[Install]                                                          \nWantedBy=default.target    \n#WantedBy=multi-user.target (NOT AVAILABLE IN USER MODE)<\/pre><\/div>\n\n\n\n<p>Example update script: (WITHOUT sudo\/root)<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"sh\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">#!\/bin\/bash\nsystemctl --user stop $servicename\ngit pull\ndotnet publish -c Release WebApi\/WebApi.csproj -o Build\/\nsystemctl --user start $servicename<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Example update script: (WITHOUT sudo\/root)<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6139","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/6139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=6139"}],"version-history":[{"count":8,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/6139\/revisions"}],"predecessor-version":[{"id":9722,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/6139\/revisions\/9722"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=6139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=6139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=6139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}