Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Custom Service / Daemon

    Scheduled Pinned Locked Moved General pfSense Questions
    16 Posts 2 Posters 3.9k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • arrmoA
      arrmo
      last edited by

      Hi,

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

      Thanks!

      1 Reply Last reply Reply Quote 0
      • H
        heper
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • arrmoA
          arrmo
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • H
            heper
            last edited by

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

            https://github.com/pfsense/FreeBSD-ports/tree/RELENG_2_3_4/net/pfSense-pkg-Avahi

            1 Reply Last reply Reply Quote 0
            • arrmoA
              arrmo
              last edited by

              Thanks!

              1 Reply Last reply Reply Quote 0
              • arrmoA
                arrmo
                last edited by

                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.

                Thoughts?

                Thanks!

                1 Reply Last reply Reply Quote 0
                • H
                  heper
                  last edited by

                  You need to write an RC file.

                  See avahi .inc file ( avahi_write_rcfile function )

                  Basically you want a script in rc.d/ directory

                  1 Reply Last reply Reply Quote 0
                  • arrmoA
                    arrmo
                    last edited by

                    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?

                    Thanks!

                    1 Reply Last reply Reply Quote 0
                    • H
                      heper
                      last edited by

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

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

                      something like:

                      
                       <installedpackages><mypackage><config><enable>on</enable>
                      			......
                                              ......</config></mypackage> 
                      .......
                      ......</installedpackages> 
                      
                      
                      1 Reply Last reply Reply Quote 0
                      • arrmoA
                        arrmo
                        last edited by

                        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)?

                        Thanks!

                        1 Reply Last reply Reply Quote 0
                        • H
                          heper
                          last edited by

                          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

                          1 Reply Last reply Reply Quote 0
                          • arrmoA
                            arrmo
                            last edited by

                            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!

                            1 Reply Last reply Reply Quote 0
                            • arrmoA
                              arrmo
                              last edited by

                              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).

                              Thanks!

                              1 Reply Last reply Reply Quote 0
                              • H
                                heper
                                last edited by

                                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.

                                1 Reply Last reply Reply Quote 0
                                • arrmoA
                                  arrmo
                                  last edited by

                                  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.

                                  Thanks!

                                  1 Reply Last reply Reply Quote 0
                                  • arrmoA
                                    arrmo
                                    last edited by

                                    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 (test.sh &) -> 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?

                                    Thanks!!!

                                    1 Reply Last reply Reply Quote 0
                                    • First post
                                      Last post
                                    Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.