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

    Shellcmd "Failing" (Boot)

    Scheduled Pinned Locked Moved General pfSense Questions
    12 Posts 3 Posters 2.8k 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.
    • C
      cmb
      last edited by

      Likely some difference in environment variables. Usually that's a PATH diff, but could be other things.

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

        That's a good point! Do you happen to know … what shell is run with shellcmd? The "normal" ssh shell is /bin/sh.

        Thanks!

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

          Well, I tried to get the environment (on Python, same language as my script). It is different, but not sure what would be critical enough to stop the program from reading from files. Here are the two results,

          SSH,
          GROUP wheel
          REMOTEHOST 192.168.2.73
          HOSTTYPE FreeBSD
          SSH_CLIENT 192.168.2.73 58179 22
          LOGNAME root
          USER root
          HOME /root
          PATH /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin
          TERM xterm
          SHELL /bin/sh
          SHLVL 1
          BLOCKSIZE K
          OSTYPE FreeBSD
          VENDOR amd
          HOST pfSense.home
          LSCOLORS exfxcxdxbxegedabagacad
          SSH_CONNECTION 192.168.2.73 58179 192.168.2.1 22
          SSH_TTY /dev/pts/1
          CLICOLOR TRUE
          PWD /root/pyTest
          MAIL /var/mail/root
          MACHTYPE x86_64

          shellcmd (pfSense GUI),
          LANG en_US.UTF-8
          OLDPWD /usr/local/www
          SCRIPT_FILENAME cd
          PWD /root/pyTest
          LOGNAME root
          USER root
          HOME /root
          PATH /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

          Thoughts?

          Thanks!

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

            Hi,

            Another approach - cron seems to have an @reboot option … does this work with pfSense?

            Thanks!

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

              FYI, tried another way - add a command to cron => set to run @reboot, and then the command is sleep 60 && "my script". Doesn't seem to run though - I assume because pfSense is recreating the crontab at boot … right? Is there a way to add a "static" entry, that pfSense doesn't remove?

              Really struggling to get a command to run "like normal" at boot ... :(.

              Thanks!

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

                Hi,

                Debugging the failing code - it's looking like the network is not up (or perhaps DNS) when running shellcmd's … is that correct? If it is - really looking for a way to run startup code after the machine is fully up and all services are on.

                Thanks!

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

                  Hi,

                  OK, still struggling with this a bit, and a very interesting finding - not in a good way … ;). I figured I would delay the execution of my script, to let the network come, but had an unintended effect - killing NAT and a bunch of other services. So I ran a test case, executing the following shellcmd,

                  sleep 120 && echo done > /root/test.log

                  It did run, but as you can see in the attachment, it stopped (blocked?) a bunch of services from starting - not good of course. Is this expected? I admit, a bit surprised to see that the shellcmd stops other items from executing.

                  So back to the drawing board - trying to figure out how to run a script / program at startup ... but now worried that if it doesn't exit (it doesn't), that it will block services from starting.

                  Thoughts?

                  Thanks!

                  ![Status - Services.png](/public/imported_attachments/1/Status - Services.png)
                  ![Status - Services.png_thumb](/public/imported_attachments/1/Status - Services.png_thumb)

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

                    OK, pulling my hair out with this one - and I don't have a lot to spare …  ;D

                    I changed the startup command, as a test => tried to make sure to daemonize the command, thinking that the parent process should exit, which would then allow the boot to continue. So the shellcmd I ran was,

                    daemon sleep 180

                    My thinking ... sleep will keep running as a child process, but daemon should exit (and I checked, it does!) -> and then boot should continue, and all the services should come up. But they don't ...  :o. Only after 3 minutes, when sleep 180 also exits => then the services finally come up (but if sleep 180 were a real command / daemon running, it may never exit).

                    Thoughts?

                    Thanks!!!

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

                      Hi,

                      Just in case anyone else has a similar issue - it seems that daemon doesn't really exit. Instead, you need to create a "real" daemon … with the single / double fork and exit approach. Once this is done - it all works.

                      Thanks!

                      1 Reply Last reply Reply Quote 0
                      • B
                        bruor
                        last edited by

                        Really wish you would have shared the actual way you are calling/running this on your end. I gave up and just put my service script in /usr/local/etc/rc.d

                        1 Reply Last reply Reply Quote 0
                        • B
                          bruor
                          last edited by

                          I just figured out, in my case, that I could just call my script like this and shellcmd launches it and continues as normal

                          daemon -f python2.7 /path/to/script/service.py

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