How to restart systemd service as a user?

How to restart systemd service as a user?

In both cases you can run systemctl [start|stop|restart] publicapi.service as user techops without giving a password. In the latter case ( polkit <= 0.105 ) the user techops could control any systemd unit. A third option would be to make the service a user service, which does not need sudo or polkit configurations.

How can we allow non-root users to control a systemd service?

– Unix & Linux Stack Exchange How could we allow non-root users to control a systemd service? With sysvinit, a sudoers entry like this would suffice: This would allow for commands such as: Now, with systemd, the service name is the final argument.

Which is the final argument in systemd service?

Now, with systemd, the service name is the final argument. I.e., the service restart would be done with: Naturally, I thought defining the command as systemctl * httpd.service would work but that would allow something like systemctl restart puppet.service httpd.service which is not the desired effect.

What is the best way to control a systemd service?

Naturally, I thought defining the command as systemctl * httpd.service would work but that would allow something like systemctl restart puppet.service httpd.service which is not the desired effect. With that being considered, what would be the best way allow non-root users to control a systemd service then?

How to control systemd only as a specific user?

To check the polkit version, just run pkaction –version. with polkit version 0.106 and higher, you can allow users to control specific systemd units. with polkit version 0.105 and lower: you can allow users to control systemd units. This unfortunately includes all systemd units and you might not want to do this.

Where do I place my systemd service units?

In general you should place your systemd units in /etc/systemd/system/ not directly in /etc/systemd/system/multi-user.target.wants. When you execute systemctl enable publicapi.service a symbolic link will be created in etc/systemd/system/multi-user.target.wants or whatever target is specified for that unit.

Can you run systemctl commands without giving a password?

Now you should be able to run the systemctl commands as user techops without giving a password by prepending sudo to the commands. The second method would be to use PolKit (was renamed from PolicyKit) to allow the user techops to control systemd services. Depending on the version of polit, you can give normal users control over systemd units.