Best way to keep daemon running

I have explicit need to have ipfs daemon running all the time on OS X. Specifically I need to be ablt to access http api on 127.0.0.1:5001

For this I have included ipfs dist and LaunchAgent plist into installation, but I have encountered few issues:

  1. Explicit need to init the daemon before running it makes it harder for OS to keep track of the process since Iā€™m forced to use script in which ipfs init && ipfs daemon are scripted. I canā€™t just feed launch agent the ā€˜ipfs daemonā€™ because it will fail if not init-ed. How to avoid it?
  2. After some time users have problems accessing http api because ipfs requres explicit permission to escalate DB version which cannot be done (as I run launchagent as root) by user and he doesnā€™t know about it. process fails on start

In general: whatā€™s the best way to keep daemon alive (maybe use js version?), I just need persistent access to http api and users donā€™t care that daemon is failing, they only see my program not working and they wonā€™t manage ipfs themselves

  1. You can start the daemon with --init, that way IPFS would run ipfs init for you, if necessary.

  2. The repo wonā€™t update by itself, only when you run ipfs init with a new repository version OR when using https://github.com/ipfs/fs-repo-migrations. If you keep using the same IPFS version, the repository will continue to work with that version.

I guess you could add some utility command that would compare a new IPFS version with the current one, and run fs-repo-migrations if different, then download and install the new version.

Thanks! That helps.

Another question: is there a good way to install IPFS as a service on Windows? I tried to do it, but IPFS doesnā€™t release launch frame when started (not return value), thus making windows believe service is still starting up. It waits for it for like 2 minutes and terminates as failure. Is there any workaround?

No worries :slight_smile:

Now Iā€™m no windows expert, but Iā€™ve always used NSSM for setting up services on Windows, most of them launched by a forever-running command.

You would basically have to do this to have IPFS as a service on Windows with NSSM:

nssm install ipfs ipfs daemon --init

And then you can either start the service via the GUI or run nssm start ipfs and it should have been launched. YMMV

You can find NSSM here: https://nssm.cc/

Thanks a lot! Iā€™ll try it out

When i start it using ā€œnssm ipfs startā€ (need to start it as Administrator), my files was missing in localhost:5001 / Files page
But when i start it using ā€œipfs daemon --initā€ my files are back there in
localhost:5001 / Files page

i installed nssm service using advised command ā€œnssm install ipfs ipfs daemon --initā€, i hope i did it via Administrator command window. Not sure what is the problem, why files are different/missing. :-/

By the way, here is advised other method to run ipfs on background as a daemon: https://github.com/ipfs/go-ipfs/issues/3572#issuecomment-275590096

you need set IPFS_PATH as system variableļ¼Œif you set IPFS_PATH as user variableļ¼Œipfs will start with config file in a place like ā€œC:\Windows\System32\config\systemprofile.ipfs\configā€,it may not your want config file and storge.