You are not logged in.

#1 2013-06-01 18:55:23

calzon65
Member
Registered: 2013-06-01
Posts: 11

[SOLVED] Help with systemd .service script

Hello,

I have been using ArchLinux (ARM version) on some “plug computers” for over a year and love it.  Recently I forced myself to move to systemd by upgrading all my computers from scratch.  I migrated all my applications and learned new ways of doing things but am having trouble with one last migration.  I run a c++ communication program that monitors a TCP port for traffic.  In the past I started this program (daemon) from an entry in rc.conf.  I have read all I can about systemd’s new approach to starting daemons (https://wiki.archlinux.org/index.php/Systemd and https://wiki.archlinux.org/index.php/Systemd/Services)

So far I created what I thought is the correct systemd .service file listed below.

[Unit]
Description=EQBCS
After=network.target

[Service]
Type=simple
ExecStart=/home/public/EQBCS/eqbcs -p 12947 -d &> /dev/null

[Install]
WantedBy=multi-user.target

I put this file in /usr/lib/systemd/system/eqbcs.service.  I then ran the following commands in the following order:

systemctl daemon-reload
systemctl enable eqbcs.service
(created a link in /etc/systemd/system/multi-user.target.wants)
systemctl start eqbcs.service

Here is output from systemctl (status)

eqbcs.service                                 loaded failed failed    EQBCS

I thought this would start the service but no luck.  I also thought maybe a reboot would work but no luck.  I verified I can start the daemon manually if I run /home/public/EQBCS/eqbcs -p 12947 -d &> /dev/null from the command line.

I think I am close, but after several hours of looking at examples of .service files and other posts, I am at a loss.  I am not one of those types who posts a question without taking the time to read the wealth of information on these boards, but I am truly out of ideas and can’t figure out what to do next.  I sincerely could use some help/advice.

Last edited by calzon65 (2013-06-01 21:18:20)

Offline

#2 2013-06-01 19:03:54

iv597
Member
From: United States
Registered: 2011-09-18
Posts: 96
Website

Re: [SOLVED] Help with systemd .service script

I'm no expert on systemd services, but I believe you need to have a Type=forking instead of simple, and get rid of "&> /dev/null" in your ExecStart.

EDIT: It may also be permissions. Systemd might or might not be able to see that script if it's in your homedir...

Last edited by iv597 (2013-06-01 19:05:17)


Currently running Arch on a Samsung Chromebook Pro (dual booted with ChromeOS), and various VPSes and Docker containers.

Dotfiles on Github

Offline

#3 2013-06-01 19:18:39

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [SOLVED] Help with systemd .service script

1. custom services belong in /etc/systemd/system, not /usr/lib/systemd/system
2. ExecStart doesn't support shell (&> /dev/null). this is explicitly mentioned in the man page btw.
3. The Type may be wrong (you probably need forking), but there is no way to tell without more information.
4. "systemctl status eqbcs" might actually give you/us helpful information.
5. we don't actually provide support for Arch Linux ARM here

Offline

#4 2013-06-01 19:35:46

calzon65
Member
Registered: 2013-06-01
Posts: 11

Re: [SOLVED] Help with systemd .service script

Thank you for all the suggestions, I moved the script to /etc/systemd/system, removed the &> /dev/null and changed the type to forked.  However in my reading about systemd, I thought if I were to use type forked, I need a PIDfile location, which I don't have and I don't know how to create.

Below is my updated .service file

Unit]
Description=EQBCS
After=network.target

[Service]
Type=forking
ExecStart=/home/public/EQBCS/eqbcs -p 12947 -d

[Install]
WantedBy=multi-user.target

Here is the output from systemctl status eqbcs

eqbcs.service - EQBCS
   Loaded: loaded (/etc/systemd/system/eqbcs.service; enabled)
   Active: inactive (dead) since Sat 2013-06-01 12:29:41 PDT; 3min 11s ago
  Process: 291 ExecStart=/home/public/EQBCS/eqbcs -p 12947 -d (code=exited, status=0/SUCCESS)
 Main PID: 292 (code=exited, status=0/SUCCESS)
   CGroup: name=systemd:/system/eqbcs.service

Jun 01 12:29:41 alarm systemd[1]: Starting EQBCS...
Jun 01 12:29:41 alarm eqbcs[291]: WARNING: Running as root NOT recommended.
Jun 01 12:29:41 alarm systemd[1]: Started EQBCS.

When I run a ps -ef I don't see the process running.

P.S. I also am running standard ArchLinux on my Intel box and get the same results.

Last edited by calzon65 (2013-06-01 19:36:08)

Offline

#5 2013-06-01 19:51:59

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Help with systemd .service script

See if you have it running with "systemd-cgls", as it should give you a tree view of your cgroups (within which that daemon should be running).  Have you tried to run the service with no Type= ?  I'm actually not sure what it defaults to, so maybe this might be repeating something you have already tried.

Also, if you are not supposed to be running it as root, then you should be using the User= parameter.  You could then have the service as eqbcs@.service and set it to User=%I.  That way you could enable eqbcs@calzon65, and it would run as you for example.

Offline

#6 2013-06-01 19:56:25

calzon65
Member
Registered: 2013-06-01
Posts: 11

Re: [SOLVED] Help with systemd .service script

Thank you for the suggestions, I believe I am getting closer to success. When I run systemctl start eqbcs.servcie it starts the service but the only way I can get out of systemctl is to ^c out.

Here is my current .service file:

[Unit]
Description=EQBCS
After=network.target

[Service]
ExecStart=/home/public/EQBCS/eqbcs -p 12947
Type=forking

[Install]
WantedBy=multi-user.target

Output from systemctl status eqbcs:

eqbcs.service - EQBCS
   Loaded: loaded (/etc/systemd/system/eqbcs.service; enabled)
   Active: failed (Result: timeout) since Sat 2013-06-01 12:48:43 PDT; 2min 11s ago
  Process: 427 ExecStart=/home/public/EQBCS/eqbcs -p 12947 (code=killed, signal=TERM)
Main PID: 396 (code=killed, signal=KILL)
   CGroup: name=systemd:/system/eqbcs.service

Jun 01 12:47:13 alarm systemd[1]: Starting EQBCS...
Jun 01 12:47:13 alarm eqbcs[427]: WARNING: Running as root NOT recommended.
Jun 01 12:47:13 alarm eqbcs[427]: EQ Box Chat Server 10.12.18
Jun 01 12:47:13 alarm eqbcs[427]: Waiting for connections on port: 12947...
Jun 01 12:48:43 alarm systemd[1]: eqbcs.service operation timed out. Terminating.
Jun 01 12:48:43 alarm systemd[1]: Failed to start EQBCS.
Jun 01 12:48:43 alarm systemd[1]: Unit eqbcs.service entered failed state.

Are there any other suggestions for settings in my .service file?

Offline

#7 2013-06-01 20:11:12

msthev
Member
Registered: 2012-04-05
Posts: 177

Re: [SOLVED] Help with systemd .service script

When you run this program from the console, does it fork to the backround?


Edit:
Ok, I read the manual. If you use -d, it should fork, and then .service needs Type=forking. Without -d it should stay in the foreground, and then Type=simple should apply.
I'd try without -d and with Type=simple.

Last edited by msthev (2013-06-01 20:16:13)

Offline

#8 2013-06-01 20:30:03

calzon65
Member
Registered: 2013-06-01
Posts: 11

Re: [SOLVED] Help with systemd .service script

Thank you everyone.  All your positive comments have helped solve this issue quickly.   It turns out the following .services file works (well at least it's working so far)

[Unit]
Description=EQBCS
After=network.target

[Service]
ExecStart=/home/public/EQBCS/eqbcs -p 12947

[Install]
WantedBy=multi-user.target

From the systemd manual, the default Type is simple, so I just left the Type out of the .service file for now.  Systemd is different from what I used previously, rc.conf, so this has been good learning experience and forces me to embrace the new path ArchLinux is following.  Hopefully this thread will help others.

Offline

Board footer

Powered by FluxBB