Should "invoke-rc.d" or "service" be used to restart services?

10,910

Solution 1

The official Debian wiki page on daemons says to use service:

# service ssh restart
Restarting OpenBSD Secure Shell server: sshd.

Functionally service and invoke-rc.d are mostly equivalent, however:

  • invoke-rc.d is the preferred command for packages' maintainer scripts, according to the command's man page
  • service has a unique --status-all option, that queries status of all available daemons

It seems like service is the user-oriented command, while invoke-rc.d is there for other uses.

Solution 2

Problem could be because your script is trying to use invoke-rc.d (which doesn't work because there are no runlevels in a docker container) before trying the service command (which will work). So change the if conditions in the script or the lazy way is make it look for a non-existent path so it will use the service command. eg:

if [ -x /xxxusr/sbin/invoke-rc.d ]; then /usr/sbin/invoke-rc.d $OMSAGENT_WS start elif [ -x /sbin/service ]; then /sbin/service $OMSAGENT_WS start

Share:
10,910

Related videos on Youtube

bernie
Author by

bernie

Updated on September 18, 2022

Comments

  • bernie
    bernie over 1 year

    I'm confused as to which is best and in which circumstances:

    invoke-rc.d apache2 restart
    

    or

    service apache2 restart
    

    Is there a real difference?

    man service has the following interesting bit:

    service runs a System V init script in as predictable environment as possible, removing most environment variables and with current working directory set to /.

    I'm interested mainly in Debian, but also Mint (also based on Debian).