How to make a script persistent across configuration restore?
-
Based on the documentation from https://docs.netgate.com/pfsense/en/latest/development/executing-commands-at-boot-time.html it seems that if you deploy a schell script it will be lost on upgrade and not restored from a configuration backup.
At the same time the persistent recommended method named shellcmd seems to allow only a very short command to be run. If I have a shell script of several lines it would be impossible to paste it there.
Is there a way to avoid this and make shell scripts to be included in the backup?
-
You can't include an entire script there, or in the config.xml backup from the base system.
If you could turn it into a shell one-liner, maybe, but that is still a bit tricky to get right.
That said, there is a Backup add-on package that might help get closer to what you are after.
-
@ssbarnea said in How to make a script persistent across configuration restore?:
Based on the documentation from https://docs.netgate.com/pfsense/en/latest/development/executing-commands-at-boot-time.html it seems that if you deploy a schell script it will be lost on upgrade and not restored from a configuration backup.
On the other hand :
I added some files and even non-pfSense, but FreeBSD packages like Munin several years (5 ?!) ago.
These files are still there - my first pfSense install was from before 2.0
Upgrading didn't removed nothing.So, if you add a file - keep a log of it. You could even use the pfSense "Notes" package where you can explain to yourself, for later usage, what you put where and why. You can even put the scripts into the Notes package - its content will be present in the config.xml that you keep aside for backup reasons.
-
@jimp said in How to make a script persistent across configuration restore?:
You can't include an entire script there, or in the config.xml backup from the base system.
Not even with the Filer package?
Edit:
I just tested it and files created with the Filer package are stored in the config.xml backup. -
@grimson said in How to make a script persistent across configuration restore?:
@jimp said in How to make a script persistent across configuration restore?:
You can't include an entire script there, or in the config.xml backup from the base system.
Not even with the Filer package?
Edit:
I just tested it and files created with the Filer package are stored in the config.xml backup.Yes, you can do it with packages, but I said "from the base system".
-
For the moment I am using Ansible to deploy the configuration which mainly solves the problem of redeploying it.
I am curious about the nature of of the scripts from /usr/local/etc/rc.d/ -- do they all need to finish during boot time or is ok if my script does something in an endless loop?
I kinda need to assure that this runs forever and more important to avoid running two copies in parallel. I do not want to create a full blown service for that.
-
@ssbarnea said in How to make a script persistent across configuration restore?:
I am curious about the nature of of the scripts from /usr/local/etc/rc.d/ -- do they all need to finish during boot time or is ok if my script does something in an endless loop?
You'd need to make the script run the background somehow, such as with
&
,nohup
,screen
, or similar. -
Thanks, I nailed it and endup with a script that does what I want, without the risk of running multiple instances in parallel.