# Creating a Daemon (win32-service) and Accessing ActionMailer

**URL:** <https://www.ruby-forum.com/t/creating-a-daemon-win32-service-and-accessing-actionmailer/148738>\
**Category:** Rails\
**Created:** [September 16, 2008, 6:56pm UTC](https://www.ruby-forum.com/t/creating-a-daemon-win32-service-and-accessing-actionmailer/148738 "2008-09-16T18:56:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [September 16, 2008, 6:56pm UTC](https://www.ruby-forum.com/t/creating-a-daemon-win32-service-and-accessing-actionmailer/148738/1 "2008-09-16T18:56:37Z")

</div>

I’m trying to create a win32-service (ruby script with Rails  
environment) utilizing the Daemon class and it currently prematurely  
exits when it encounters a method of mine that calls a delivery via  
ActionMailer.

Here is the process:  
Windows Service (Ruby script Daemon class)  
|  
v  
MyModel.save (from within the Ruby script via requiring the Rails  
environment)  
|  
v  
after\_create :deliver\_notification

This causes my Daemon to exit. Has anyone tried anything similar? I’ve  
tried breaking the MyModel.save off onto another thread with no luck.

I don’t know if the problem is the time required to deliver the message  
or if it’s because ActionMailer uses its own Daemon.

Anyone have any thoughts?

---

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [September 16, 2008, 8:42pm UTC](https://www.ruby-forum.com/t/creating-a-daemon-win32-service-and-accessing-actionmailer/148738/2 "2008-09-16T20:42:18Z")

</div>

Just an update, the exception I am capturing is a “Bad file descriptor”  
exception. The actionmailer model and method work well outside the  
windows service.

---

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [September 16, 2008, 10:08pm UTC](https://www.ruby-forum.com/t/creating-a-daemon-win32-service-and-accessing-actionmailer/148738/3 "2008-09-16T22:08:47Z")

</div>

Permissions problem maybe? I have a vague association in my mind  
between that error and server not being accessible…

What credentials does your service run under? Is it an account  
w/network permissions?

---

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [September 16, 2008, 11:21pm UTC](https://www.ruby-forum.com/t/creating-a-daemon-win32-service-and-accessing-actionmailer/148738/4 "2008-09-16T23:21:11Z")

</div>

From the command line in an interactive session? That’s != the  
environment you get when you’re running from a service…

If you haven’t already, just for a goof, temporarily have the service  
run under your domain credentials & see if it makes a difference.

---

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [September 16, 2008, 11:46pm UTC](https://www.ruby-forum.com/t/creating-a-daemon-win32-service-and-accessing-actionmailer/148738/5 "2008-09-16T23:46:47Z")

</div>

Roy P. wrote:

> From the command line in an interactive session? That’s != the  
> environment you get when you’re running from a service…
> 
> If you haven’t already, just for a goof, temporarily have the service  
> run under your domain credentials & see if it makes a difference.

Sadly that didn’t make a difference. I even tried to log out and back  
in again, which still caused the same exception to be logged.

Can a daemon such as ActionMailer’s delivery methods be called from  
within another daemon (win32-service)?

Vic.

---

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [September 17, 2008, 9:34pm UTC](https://www.ruby-forum.com/t/creating-a-daemon-win32-service-and-accessing-actionmailer/148738/6 "2008-09-17T21:34:14Z")

</div>

I have what seems to be a solution. The problem was unrelated to  
ActionMailer. In reality the problem was occurring because of a few  
constants that were declared in multiple places. When MyModel  
re-declared these constants this error (Bad File Descriptor) would be  
being thrown.

---

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [September 16, 2008, 11:14pm UTC](https://www.ruby-forum.com/t/creating-a-daemon-win32-service-and-accessing-actionmailer/148738/7 "2008-09-16T23:14:30Z")

</div>

Roy P. wrote:

> Permissions problem maybe? I have a vague association in my mind  
> between that error and server not being accessible…
> 
> What credentials does your service run under? Is it an account  
> w/network permissions?

Thanks for replying! I seem to have full permissions from the command  
line and everything else works from the service except the mailer. I  
don’t forward any credentials to the mailer concerning my actual login  
either.
