Interaction with services not handled by iMSCP

  • Hello,


    I would like to know which would be the best way to interact with a service not handled by iMSCP? Do I have to use iMSCP::Execute for service XYZ reload or is there a better way doing this? I want to reload postsrsd service with the listener.
    Thanks in advance for any feedback.


    Regards Jörg

    (Ubuntu 16.04, i-MSCP 1.5.1, php-Fpm, Plugins: ClamAV, CronJobs, InstantSSH, LetsEncrypt, Mailgraph, Monitorix, OpenDKIM, PhpSwitcher, PolicydSPF, Postscreen, RecaptchaPMA, RoundcubePlugins, ServerDefaultPage, SpamAssassin, YubiKeyAuth)

  • @UncleJ


    You shouldn't execute the service command by yourself, even by using the execute() function that is provided by i-MSCP core.


    i-MSCP core provides service providers which are meant to handle services in "safe" way. Those providers are meant to provide a standardized way to handle services in i-MSCP whatever the system init used on your system (sysvinit, upstart, systemd).


    For instance, let's imagine you want handle an external service such as fail2ban in a listener file. You could do



    Note that the iMSCP::Service class is a high level interface for i-MSCP service providers (sysvinit, upstart, systemd). With the above code, the fail2ban service would be restarted (or started if not already) when the whatever_event_you_want_listen would be triggered by i-MSCP. Of course, you can use the iMSCP::Service class outside of an event listener context.


    See also:

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • @Nuxwin,


    thanks for the reply - I was not sure if iMSCP::Service is also able to handle all services or just the iMSCP handled ones.


    Regards Jörg

    (Ubuntu 16.04, i-MSCP 1.5.1, php-Fpm, Plugins: ClamAV, CronJobs, InstantSSH, LetsEncrypt, Mailgraph, Monitorix, OpenDKIM, PhpSwitcher, PolicydSPF, Postscreen, RecaptchaPMA, RoundcubePlugins, ServerDefaultPage, SpamAssassin, YubiKeyAuth)