Setting up a startup service

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting up a startup service

asdf asdf
Hello all,

I have built an Erlang program and created a release using rebar3 release. To run this program, I use the command:

./_build/default/rel/program/bin/program start

What I would like to do now is have this program start on startup whenever the box boots or whenever the VM crashes. I have to use a RHEL 7 box for this, so I am using systemd. I created a service below:

[Unit]
Description=program                                                          
After=network.target

[Service]
Type=simple                                                                      
User=root
ExecStart=/home/root/repos/program/_build/default/rel/program/bin/program start         
Restart=on-abort

[Install]                                                                        
WantedBy=multi-user.target  


This doesn’t work however - I get the following output:

Dec 18 17:43:59 localhost.localdomain systemd[1]: Started program.
Dec 18 17:43:59 localhost.localdomain systemd[1]: Starting program… 

(It is odd that it says “started program” followed by “starting program”…)

Now here is the interesting part - if I switch out “start” with “console” , I get good output - I get the successful start message. But then a crash… :

Dec 18 17:45:40 localhost.localdomain program[14167]: 17:45:40.429 [info] Application program started on node 'program@192.168.1.101'
Dec 18 17:45:40 localhost.localdomain program[14167]: Eshell V8.2.2  (abort with ^G)
Dec 18 17:45:40 localhost.localdomain program 14167]: (program@192.168.1.101)1> *** Terminating erlang ('program@192.168.1.101’)

This crash is expected though, because I tried to start it in console but it was a background process. My point though is that it starts up, but for some unknown reason it is exiting. On top of that, all of the log files in _build/default/rel/program/log are empty, so I’m not getting any valuable info on why it isn’t starting.

And to clarify, I have copy/pasted the ExecStart command from the file to the command line and it works when it is run from the command line, so this isn’t a path issue.

Does anyone have any idea as to what I am doing wrong?

Thank you in advance.


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Setting up a startup service

Fred Youhanaie-2
Hi

systemd doesn't work when programs (services) detach and run in the background.

Try starting it with "foreground" instead of start or console.

Cheers,
Fred


On 18/12/17 22:55, asdf asdf wrote:

> Hello all,
>
> I have built an Erlang program and created a release using rebar3 release. To run this program, I use the command:
>
> *./_build/default/rel/program/bin/program start*
>
> What I would like to do now is have this program start on startup whenever the box boots or whenever the VM crashes. I have to use a RHEL 7 box for this, so I am using systemd. I created a service below:
>
> *[Unit]*
> *Description=program *
> *After=network.target*
> *
> *
> *[Service]*
> *Type=simple *
> *User=root*
> *ExecStart=/home/root/repos/program/_build/default/rel/program/bin/program start *
> *Restart=on-abort*
> *
> *
> *[Install]
> *
> *WantedBy=multi-user.target *
>
>
> This doesn’t work however - I get the following output:
>
> *Dec 18 17:43:59 localhost.localdomain systemd[1]: Started program.
> *
> *Dec 18 17:43:59 localhost.localdomain systemd[1]: Starting program… *
>
> (It is odd that it says “started program” followed by “starting program”…)
>
> Now here is the interesting part - if I switch out “start” with “console” , I get good output - I get the successful start message. But then a crash… :
>
> *Dec 18 17:45:40 localhost.localdomain program[14167]: 17:45:40.429 [info] Application program started on node 'program@192.168.1.101'*
> *Dec 18 17:45:40 localhost.localdomain program[14167]: Eshell V8.2.2  (abort with ^G)*
> *Dec 18 17:45:40 localhost.localdomain program 14167]: (program@192.168.1.101)1> *** Terminating erlang ('program@192.168.1.101’)*
>
> This crash is expected though, because I tried to start it in console but it was a background process. My point though is that it starts up, but for some unknown reason it is exiting. On top of that,
> all of the log files in _build/default/rel/program/log are empty, so I’m not getting any valuable info on why it isn’t starting.
>
> And to clarify, I have copy/pasted the ExecStart command from the file to the command line and it works when it is run from the command line, so this isn’t a path issue.
>
> Does anyone have any idea as to what I am doing wrong?
>
> Thank you in advance.
>
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Setting up a startup service

Ryan Auger
This was it. Thank you Fred.

On Dec 18, 2017, 6:18 PM -0500, Fred Youhanaie <[hidden email]>, wrote:
Hi

systemd doesn't work when programs (services) detach and run in the background.

Try starting it with "foreground" instead of start or console.

Cheers,
Fred


On 18/12/17 22:55, asdf asdf wrote:
Hello all,

I have built an Erlang program and created a release using rebar3 release. To run this program, I use the command:

*./_build/default/rel/program/bin/program start*

What I would like to do now is have this program start on startup whenever the box boots or whenever the VM crashes. I have to use a RHEL 7 box for this, so I am using systemd. I created a service below:

*[Unit]*
*Description=program *
*After=network.target*
*
*
*[Service]*
*Type=simple *
*User=root*
*ExecStart=/home/root/repos/program/_build/default/rel/program/bin/program start *
*Restart=on-abort*
*
*
*[Install]
*
*WantedBy=multi-user.target *


This doesn’t work however - I get the following output:

*Dec 18 17:43:59 localhost.localdomain systemd[1]: Started program.
*
*Dec 18 17:43:59 localhost.localdomain systemd[1]: Starting program… *

(It is odd that it says “started program” followed by “starting program”…)

Now here is the interesting part - if I switch out “start” with “console” , I get good output - I get the successful start message. But then a crash… :

*Dec 18 17:45:40 localhost.localdomain program[14167]: 17:45:40.429 [info] Application program started on node 'program@192.168.1.101'*
*Dec 18 17:45:40 localhost.localdomain program[14167]: Eshell V8.2.2  (abort with ^G)*
*Dec 18 17:45:40 localhost.localdomain program 14167]: (program@192.168.1.101)1> *** Terminating erlang ('program@192.168.1.101’)*

This crash is expected though, because I tried to start it in console but it was a background process. My point though is that it starts up, but for some unknown reason it is exiting. On top of that,
all of the log files in _build/default/rel/program/log are empty, so I’m not getting any valuable info on why it isn’t starting.

And to clarify, I have copy/pasted the ExecStart command from the file to the command line and it works when it is run from the command line, so this isn’t a path issue.

Does anyone have any idea as to what I am doing wrong?

Thank you in advance.



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Setting up a startup service

Jesper Louis Andersen-2
Alternatively, you can try using the `forking` type in systemd and then set up things as it were a forking process. But maybe that won't pan out too well? It would be what I would try if possible. OTOH, it looks like most other services are going the `simple` route nowadays, so perhaps it is better to cater for that setup variant.


On Tue, Dec 19, 2017 at 12:21 AM Ryan Auger <[hidden email]> wrote:
This was it. Thank you Fred.

On Dec 18, 2017, 6:18 PM -0500, Fred Youhanaie <[hidden email]>, wrote:
Hi

systemd doesn't work when programs (services) detach and run in the background.

Try starting it with "foreground" instead of start or console.

Cheers,
Fred


On 18/12/17 22:55, asdf asdf wrote:
Hello all,

I have built an Erlang program and created a release using rebar3 release. To run this program, I use the command:

*./_build/default/rel/program/bin/program start*

What I would like to do now is have this program start on startup whenever the box boots or whenever the VM crashes. I have to use a RHEL 7 box for this, so I am using systemd. I created a service below:

*[Unit]*
*Description=program *
*After=network.target*
*
*
*[Service]*
*Type=simple *
*User=root*
*ExecStart=/home/root/repos/program/_build/default/rel/program/bin/program start *
*Restart=on-abort*
*
*
*[Install]
*
*WantedBy=multi-user.target *


This doesn’t work however - I get the following output:

*Dec 18 17:43:59 localhost.localdomain systemd[1]: Started program.
*
*Dec 18 17:43:59 localhost.localdomain systemd[1]: Starting program… *

(It is odd that it says “started program” followed by “starting program”…)

Now here is the interesting part - if I switch out “start” with “console” , I get good output - I get the successful start message. But then a crash… :

*Dec 18 17:45:40 localhost.localdomain program[14167]: 17:45:40.429 [info] Application program started on node '[hidden email]'*
*Dec 18 17:45:40 localhost.localdomain program[14167]: Eshell V8.2.2  (abort with ^G)*
*Dec 18 17:45:40 localhost.localdomain program 14167]: ([hidden email])1> *** Terminating erlang ('[hidden email]’)*

This crash is expected though, because I tried to start it in console but it was a background process. My point though is that it starts up, but for some unknown reason it is exiting. On top of that,
all of the log files in _build/default/rel/program/log are empty, so I’m not getting any valuable info on why it isn’t starting.

And to clarify, I have copy/pasted the ExecStart command from the file to the command line and it works when it is run from the command line, so this isn’t a path issue.

Does anyone have any idea as to what I am doing wrong?

Thank you in advance.



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions