Why does it use systemctl is-active instead of systemctl is-enabled?
Relevant part of .install file for my question.
post_install() {
msg "Attempting to enable Samba services..."
systemctl is-active smb >/dev/null || systemctl enable smb
systemctl is-active nmb >/dev/null || systemctl enable nmb
add_group
echo ""
msg "Samba services should now be enabled."
msg "Please add new users to 'sambashare' group."
msg "Reboot your system, so changes will take affect."
echo ""
}
post_remove() {
msg "Attempting to disable Samba services..."
! systemctl is-active smb >/dev/null || systemctl disable smb
! systemctl is-active nmb >/dev/null || systemctl disable nmb
! getent group sambashare || groupdel sambashare
echo ""
msg "Samba services should now be disabled. Reboot your system."
echo ""
}
Why does it test if the service is active instead of testing if the service is enabled in order to decide if it has to enable or disable the service?
The current situation has the following consequence: smb.service or nmb.service might not be disabled after uninstalling manjaro-settings-samba
if, for example, they got stopped manually by an adminstrator or have failed to start for whatever reason.
In the second case, where a unit has failed to start, notice that systemctl is-active UNIT
has a non-zero exit status, which means that ! systemctl is-active UNIT
will return 0 as the exit status. Therefore, if someone uninstall manjaro-settings-samba
while smb.service and/or nmb.service are in a failed state, they won't get disabled since ! systemctl is-active UNIT
returns 0 as the exit status.
[awesome@i56400 ~]$ systemctl status smb.service
● smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2019-07-07 13:22:42 EDT; 17min ago
Docs: man:smbd(8)
man:samba(7)
man:smb.conf(5)
Process: 734 ExecStart=/usr/bin/smbd --foreground --no-process-group $SMBDOPTIONS (code=exited, status=1/FAILURE)
Main PID: 734 (code=exited, status=1/FAILURE)
Jul 07 13:22:42 i56400 systemd[1]: Starting Samba SMB Daemon...
Jul 07 13:22:42 i56400 systemd[1]: smb.service: Main process exited, code=exited, status=1/FAILURE
Jul 07 13:22:42 i56400 systemd[1]: smb.service: Failed with result 'exit-code'.
Jul 07 13:22:42 i56400 systemd[1]: Failed to start Samba SMB Daemon.
[awesome@i56400 ~]$ systemctl status nmb.service
● nmb.service - Samba NMB Daemon
Loaded: loaded (/usr/lib/systemd/system/nmb.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2019-07-07 13:22:42 EDT; 17min ago
Docs: man:nmbd(8)
man:samba(7)
man:smb.conf(5)
Process: 733 ExecStart=/usr/bin/nmbd --foreground --no-process-group $NMBDOPTIONS (code=exited, status=1/FAILURE)
Main PID: 733 (code=exited, status=1/FAILURE)
Jul 07 13:22:41 i56400 systemd[1]: Starting Samba NMB Daemon...
Jul 07 13:22:42 i56400 systemd[1]: nmb.service: Main process exited, code=exited, status=1/FAILURE
Jul 07 13:22:42 i56400 systemd[1]: nmb.service: Failed with result 'exit-code'.
Jul 07 13:22:42 i56400 systemd[1]: Failed to start Samba NMB Daemon.
[awesome@i56400 ~]$ systemctl is-active smb.service
failed
[awesome@i56400 ~]$ echo $?
3
[awesome@i56400 ~]$ ! systemctl is-active smb.service
failed
[awesome@i56400 ~]$ echo $?
0
[awesome@i56400 ~]$ systemctl is-active nmb.service
failed
[awesome@i56400 ~]$ echo $?
3
[awesome@i56400 ~]$ ! systemctl is-active nmb.service
failed
[awesome@i56400 ~]$ echo $?
0
[awesome@i56400 ~]$
Suggested fix: Use "systemctl is-enabled" instead of "systemctl is-active".
Also, I would change the following messages.
-
Reboot your system, so changes will take affect
forReboot your system, so changes will take effect.