service: Instant service activation

I'm creating a software that allows to instantly enable systemd services after their installation or upgrade, without the need to log out, for all logged in users.

That's something that systemctl can do for system services, but not on its own for user services. This tool is aimed to activate or reload any service globally with a single command.

How would you like this to be like? Any feature o suggestion you would like to see?

Doesn't needrestart already do that?

$ sudo needrestart
Scanning processes...                                                                                                                                                                     
Scanning candidates...                                                                                                                                                                    
Scanning processor microcode...                                                                                                                                                           
Scanning linux images...                                                                                                                                                                  

Pending kernel upgrade!

Running kernel version:

  The currently running kernel version is not the expected kernel version 5.1.8-1-MANJARO.

Restarting the system to load the new kernel will not be handled automatically, so you should consider rebooting. [Return]

Failed to check for processor microcode upgrades.

Restarting services...
Services to be restarted:
Restart ┬źModemManager.service┬╗? [yNas?] n
Restart ┬źNetworkManager.service┬╗? [yNas?] n
Restart ┬źaccounts-daemon.service┬╗? [Ynas?] n
Restart ┬źanbox-container-manager.service┬╗? [Ynas?] n
Restart ┬źbluetooth.service┬╗? [Ynas?] n
Restart ┬źbolt.service┬╗? [Ynas?] n
Restart ┬źclightd.service┬╗? [Ynas?] n
Restart ┬źcolord.service┬╗? [Ynas?] n
Restart ┬źdbus.service┬╗? [yNas?] n
Restart ┬źgdm.service┬╗? [yNas?] n
Restart ┬źlvm2-lvmetad.service┬╗? [Ynas?] n
Restart ┬źorg.cups.cupsd.service┬╗? [Ynas?] n
Restart ┬źpamac-system.service┬╗? [Ynas?] n
Restart ┬źpolkit.service┬╗? [Ynas?] n
Restart ┬źsystemd-journald.service┬╗? [Ynas?] n
Restart ┬źsystemd-logind.service┬╗? [yNas?] n
Restart ┬źsystemd-machined.service┬╗? [Ynas?] n
Restart ┬źsystemd-timesyncd.service┬╗? [Ynas?] n
Restart ┬źsystemd-udevd.service┬╗? [Ynas?] n
Restart ┬źudisks2.service┬╗? [Ynas?] n
Restart ┬źupower.service┬╗? [Ynas?] n
Restart ┬źwpa_supplicant.service┬╗? [yNas?] n
Service restarts being deferred:
 systemctl restart ModemManager.service
 systemctl restart NetworkManager.service
 systemctl restart accounts-daemon.service
 systemctl restart anbox-container-manager.service
 systemctl restart bluetooth.service
 systemctl restart bolt.service
 systemctl restart clightd.service
 systemctl restart colord.service
 systemctl restart gdm.service
 systemctl restart lvm2-lvmetad.service
 systemctl restart org.cups.cupsd.service
 systemctl restart pamac-system.service
 systemctl restart polkit.service
 systemctl restart systemd-journald.service
 systemctl restart systemd-logind.service
 systemctl restart systemd-machined.service
 systemctl restart systemd-timesyncd.service
 systemctl restart systemd-udevd.service
 systemctl restart udisks2.service
 systemctl restart upower.service
 systemctl restart wpa_supplicant.service

No containers need to be restarted.

User sessions running outdated binaries:
 gdm @ user manager service: at-spi-bus-laun[1094], pulseaudio[1165], systemd[909]
 yochanan @ session #2: chrome[2712,2722,2727], chrome-sandbox[2721,2724], conky[2641], copyq[1963], dbxfs[20960], gdm-session-wor[1586], gdm-x-session[1631], gnome-keyring-d[1613],
  gnome-session-b[1650], gnome-shell[1719], gsd-printer[1935], nacl_helper[2725], python3[1977], slack[14621,14624]
 yochanan @ user manager service: at-spi-bus-laun[1679], gvfsd[1739], nautilus[12836], pulseaudio[1787], systemd[1600]
1 Like

I will check.

For system services:

sudo systemctl enable --now your.service

sudo systemctl daemon-reload

For user services:

systemctl --user enable --now your.service

systemctl --user daemon-reload


When used with enable , the units will also be started. When used with disable or mask , the units will also be stopped. The start or stop operation is only carried out when the respective enable or disable operation has been successful.

1 Like

There's a problem there if the command is issued during package installation. The command will be run as superuser, so for user services it will fail.

Furthermore it should apply to all users logged in, not only to the sudoer.

If the script is being run as superuser the you could try sudo -u $USER to execute the operation as the user. $USER would need to be defined as the currently logged in user, or you could try using sudo -u $LOGNAME.

1 Like

Yeah, I know. That's what I'm writing, a command to run that recursively to all logged in users.

Except if needrestart already does the job.

1 Like