Custom Service / Daemon

  • Hi,

    Is there an easy way to create my own custom service / daemon, and even have it show up in the services list?


  • sure. almost every package shows up in services list ….
    if you figure out how to create a custom package, then adding it to the services list is fairly straightforward

  • Working on it …  ;D. I admit, having a heck of a time figuring out where the services / daemon files (rc.conf, etc.) are stored for packages.

  • the 'avahi' package is fairly clean & not too complex to use as an example

  • Thanks!

  • Ok, getting there … :). My custom service file works now, but it's not starting on boot ... I added the appropriate enable to /etc/rc.conf.local, and rcvar seems to see it, but it's not auto-starting.



  • You need to write an RC file.

    See avahi .inc file ( avahi_write_rcfile function )

    Basically you want a script in rc.d/ directory

  • Hi,

    Yes, I did, and that's all working - I can start, stop, status, etc. my service. Works great, and if I run
    service myservice rcvar

    -> It shows as enabled. But it still doesn't start on boot. Not sure if pfSense has blocked this "normal" operation?


  • can you start/stop/restart it from GUI (status–>services) ?

    do you have valid package entries in the config.xml of pfSense ?

    something like:


  • Hi,

    No, I haven't installed a package (not sure how to do that), and can't see it in the GUI. Rather, it's based on an rc.d script - that should be supported (by FreeBSD underneath), no? Or are services only enabled / disabled by pfSense (as packages)?


  • Most packages are enabled/disabled by GUI check boxes… If it's disabled, it doesn't start.

    If you don't wish to create a GUI & complementary XML structure, then you can try the shellcmd package to start things at boot

  • That makes sense, thanks! I was thinking that the "stock" FreeBSD mechanisms would still work, but it seems like this is not the case - and then shellcmd is likely the best answer.

    Thanks again!

  • OK, a slight glitch … ;)

    I can run my commands (from the SSH shell), no issues at all - they work (start, stop, restart, status, etc. ... even rcvar). But, started as a shellcmd, they seem to mess with other services. No idea why, as they really shouldn't interact - and funny as it is, one of my two services starts (shellcmd), not the other => but both fine if I start them after boot from a shell.

    So I figured - let me add a sleep in front of them. No joy, this actually seemed to block boot up - but it shouldn't, no? Or do I need the shell command to run in the background?

    In any case - any thoughts? It's very odd - and for now I have to disable it. But thinking these commands should run in parallel / offline (so to speak).


  • They won't run in parallel, because some things depend on others…..start order is important.

    You could probably work around it somehow. Maybe sending it to bg or forking.

  • Let me play a bit, thanks! Yes, thinking the same - bg may do it … my service uses daemon, so it does fork, it's just some sort of odd sequence thing I believe (like you say). And my service really doesn't touch any of the others (it just runs a Python script to monitor some files).

    I was thinking sleep would let me delay my shellcmd - really, want it (say) 30 seconds after all else is up, just not sure of a good way to do that.


  • OK, pulling my hair out with this - and I don't have enough to spare …  ;)

    If I try to start my services (which use daemon, so fork to the background) ... they block other services from starting (actually, one does, the other doesn't - but they both just call Python ... very odd). So I tried a shellcmd in the bg (trailing &) -> then pfSense doesn't even boot fully! I have to go to the console, press Enter to get it to continue (and then again to skip changing the configuration).

    Next I tried a super-complex script (ls -alF) ... ;D. Ran that in the background ( &) -> again, pfSense won't boot, it gets stuck, have to press Enter on the console. But after that, all the services have started at least). But boot shouldn't stop, agreed?

    So very confused about this, and why it's not working. Has anyone else been able to get it to work?


Log in to reply