Shellcmd "Failing" (Boot)



  • Hi,

    I have a Python script that I can run manually - works great. If I try exactly the same command (i.e. command line to execute it) from shellcmd (late in boot) - it fails … or rather, it sort of starts, but doesn't run properly. But again, copy and paste, run the same command from ssh ... and it's working fine.

    Is there another way to run a command after boot (say, wait 30 seconds)? It's odd that this is failing, but it seems to do so reliably (unfortunately). Or are there good ideas to try to debug what is "missing" when the shellcmd is run?

    Thanks!



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



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

    Thanks!



  • 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!



  • Hi,

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

    Thanks!



  • 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!



  • 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!



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



  • 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!!!



  • 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!



  • 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



  • 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