Hi all. First time creating a thread here, please be gentle!
I have an Mix release executable that works fine when started normally, but appears not to run when launched as a daemon. Is this a problem that others have encountered?
When I start it explicitly with start it initialises with no errors, and works as expected. But when started with daemon or daemon_iex it starts with no output and performs none of the actions I expect it to. In fact, the command acts like a no-op on the shell.
Further more, no output of any kind is redirected to the /tmp folders, which is making this issue extremely hard to debug.
Interestingly, the issue I believe I’ve encountered sounds very similar to the one found for Distillery on Github here:
So I suspect there could well be a shared underlying cause.
Any ideas, please?
Edit - Further details, I’d encountered this issue running Elixir 1.9.1 (compiled with Erlang/OTP 20), on Ubuntu 16.0.4 via VirtualBox on Windows. I know VM setups can occasionally mess with common OS settings, and security features, so if that might be a potential issue, advice will be welcome.
Do you actually output to ./tmp/log? And if so what is the line of code that does that and in what function in what module is it located?
Creating a file is enough. A logger ‘might’ be enough if it’s linked to something persistent like journald/syslog or a file output or so. You won’t be able to IO.puts or log to the screen or so since it’s a daemon (no stdin/stdout). ^.^
I’m wondering if this is an early version issue too. Tbf though, Mix Releases do appear to be a little more user friendly than Distillery. Plus it’s one less dependency (I’m one of those devs…).
As it does run in start mode, I could just use systemd and make a service of the app instead…
But I’d really like to know why one mode works, and the other mode doesn’t.
Issues like that are a code smell. But in this case, I’m not entirely sure if that issue is in my code, as I can reproduce the issue by merely creating a fresh Mix project with barely any code, except for the releases config (thank to help from the Elixir Slack channel).
Well lets see what folder permission you have. In a terminal window:
I want to see what Access: (#) Uid: (#/user) Gid: (#/user )
What I think is going on is that this program should install its own user and file privileges, and somehow that got overlooked or somehow didn’t happen when it was installed.
If this program doesn’t install its own user, it will not run in daemon mode according to the deamon Unix module in the OS (Ubuntu). The only way for it to run without setting as its own user is to run it as root. But I would not advise that.
Just checked daemon mode with one of my apps on Ubuntu 18.04, seems to work fine - the app is working and there is output in the tmp directory (just to be clear: it’s not /tmp, but a ./tmp in the release dir).
So if there is an issue it might have to do with the OS running in a VM.
yes, they all spawn it that way, but lets get back to the person that has trouble, which file permissions being out of wack is not out of the norm for linux, especially for it being a source code and not packaged and in a distro channel.
The difference between running it on the command line vs a process is that the user is different. On the command line, the user is the user account . The daemon, the program is the user and should have a user account that at least assigned to the same file access group as the user, but usually set as a separate user group. The rules for a program to run as a daemon are: its own user account, and must not be root or a part of root user group.