CLI commands to start and stop services



  • What are the CLI commands to start and stop a service, e.g. Avahi, in pfSense. I tried "service avahi restart" in the Shell but got an "avahi does not exists …" error.



  • 
     WAN (wan)       -> em0        -> v4/DHCP4: 74/21
     LAN (lan)       -> em1        -> v4: 10.0.0.1/24
     IPV6_TUNNEL (opt1) -> gif0       -> v6: 2001:ac7::2/128
     OVPN_SHIL (opt2) -> ovpnc1     -> v4: 192.168.222.2/32
     WIFI (opt3)     -> dc0        -> v4: 192.168.101.254/24
    
     0) Logout (SSH only)                  9) pfTop
     1) Assign Interfaces                 10) Filter Logs
     2) Set interface(s) IP address       11) Restart webConfigurator
     3) Reset webConfigurator password    12) pfSense Developer Shell
     4) Reset to factory defaults         13) Update from console
     5) Reboot system                     14) Disable Secure Shell (sshd)
     6) Halt system                       15) Restore recent configuration
     7) Ping host                         16) Restart PHP-FPM
     8) Shell
    
    Enter an option: 12
    
    Starting the pfSense developer shell....
    
    Welcome to the pfSense developer shell
    
    Type "help" to show common usage scenarios.
    
    Available playback commands:
         changepassword checkopenvpn_status disablecarp disabledhcpd disablereferercheck enableallowallw                                                        
    an enablecarp enablesshd externalconfiglocator generateguicert gitsync installpkg listpkg removepkgc                                                        
    onfig removeshaper restartdhcpd restartipsec svc tmp2 uninstallpkg 
    
    pfSense shell: playback svc
    
    Playback of file svc started.
    
    Usage: playback svc <action><service name="">[service-specific options]
    
    Examples:
    playback svc stop dhcpd
    playback svc restart openvpn client 2
    playback svc stop captiveportal zone1
    
    pfSense shell:</service></action> 
    

    https://doc.pfsense.org/index.php/Using_the_PHP_pfSense_Shell



  • @oletuv:

    What are the CLI commands to start and stop a service, e.g. Avahi, in pfSense. I tried "service avahi restart" in the Shell but got an "avahi does not exists …" error.

    service avahi-daemon.sh start
    service avahi-daemon.sh stop
    service avahi-daemon.sh restart



  • If you want to schedule it via Cron, you can use something like

    15    9    *    *    *    root    /usr/local/sbin/pfSsh.php playback svc restart avahi
    


  • @luckman212:

    If you want to schedule it via Cron, you can use something like

    15    9    *    *    *    root    /usr/local/sbin/pfSsh.php playback svc restart avahi
    

    I know this thread is quite old, but I need to run a command like this via Putty's plink command line.  But I keep getting

    putty.exe>plink -ssh -pw somepasswd root@192.168.0.1 "/usr/local/sbin/pfSsh.php playback svc restart openvpn client 1"
    The process cannot access the file because it is being used by another process.
    

    Any help is appreciated



  • your command looks (mostly) ok – that error seems to be from your Windows machine, not the remote pfSense system. It looks like you have "putty.exe>" in front of the plink.exe on your commandline. Why? that is not correct...
    https://the.earth.li/~sgtatham/putty/0.70/htmldoc/Chapter7.html#plink-usage-interactive