Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systemd Installation #2570

Closed
neilromig opened this issue Nov 20, 2016 · 30 comments
Closed

Systemd Installation #2570

neilromig opened this issue Nov 20, 2016 · 30 comments

Comments

@neilromig
Copy link

In both 3.7 and 3.8 installation fails initially because Arch Linux is systemd only and has no /etc/init.d so it would be good if traccar.run checked for systemd or prompted during install so it doesn't fail.

@tananaev
Copy link
Member

Does it have /etc/rcX.d folders?

@CVSz
Copy link
Contributor

CVSz commented Nov 20, 2016

arch linux

Systemd
systemd is the default init framework, replacing initscripts. The services which are started by systemd can be found in the subfolders of /etc/systemd/system/. Services can be enabled using the systemctl command. For more information about systemd and how to write autostart scripts for it, see at systemd. To autostart scripts for specific users, see systemd/User.

https://www.freedesktop.org/software/systemd/man/systemd.service.html#Examples

i think can you used traccar-other-3.8 and manual create service runing by traccar.sh

First, create service file (/etc/systemd/system/traccar.service):

[Unit]
Description=Traccar Server Service

[Service]
Type=simple
ExecStart=/usr/local/traccar/traccar.sh

[Install]
WantedBy=multi-user.target

Now enable and run it:

# systemctl enable traccar.service
# systemctl start traccar.service

@neilromig
Copy link
Author

neilromig commented Nov 20, 2016

Distros like debian use systemd but convert SysV init scripts into service files. Arch is purely systemd and has no init.d or rcX.d folders. All is done using systemd only. Traccar 3.7 worked OK if I fooled traccar.run into thinking it was on debian (by creating /etc/lsb-release) - otherwise only setting USE_SYSTEMD=true was ineffective. Perhaps if the /etc/systemd hierarchy is present the install should create systemd .service files only?

@CVSz
Copy link
Contributor

CVSz commented Nov 20, 2016

yes, i think but i'm not test on arch linux i see docs only
can you try to download traccar-other-3.8 and test again

@neilromig
Copy link
Author

I have installed traccar-other-3.8, though it is not really an "installation" just unzipping the archive! It will start by running traccar.sh directly from /opt/traccar folder, but the systemd service file fails with no error messages, the journalctl says traccar started, and the file /tmp/traccar-pid still exists though no process present. I tried putting "cd /opt/traccar" into traccar.sh but still systemctl start fails.
I will try and find out the problem with systemctl...

@CVSz
Copy link
Contributor

CVSz commented Nov 20, 2016

@neilromig
Copy link
Author

neilromig commented Nov 20, 2016

I will check it out, though I have it working now,

My current traccar.service file is:

[Unit]
Description=traccar-other
After=syslog.target
[Service]
Type=forking
WorkingDirectory=/opt/traccar
ExecStart=/opt/traccar/traccar.sh start
ExecStop=/opt/traccar/traccar.sh stop
PIDFile=/tmp/traccar-pid
[Install]
WantedBy=multi-user.target

(Perhaps I should mention there is an Arch user-contributed package for traccar but it is compile from source and i did not want to bother installing the compilation packages...)

@tananaev
Copy link
Member

New version of Traccar is using YAJSW to run Traccar as a native service. I don't think it supports systemd.

@BotoX
Copy link

BotoX commented Nov 22, 2016

I don't have a traccar.sh in the traccar folder?
I tried to run it like so:

$ bin/startDaemon.sh 
++++++++++ YAJSW SET ENV ++++++++++
openjdk version "1.8.0_112"
OpenJDK Runtime Environment (build 1.8.0_112-b15)
OpenJDK 64-Bit Server VM (build 25.112-b15, mixed mode)
wrapper home : /opt/traccar
configuration: /opt/traccar/conf/wrapper.conf
openjdk version "1.8.0_112"
OpenJDK Runtime Environment (build 1.8.0_112-b15)
OpenJDK 64-Bit Server VM (build 25.112-b15, mixed mode)
---------- YAJSW SET ENV ----------
++++++++++ YAJSW SET ENV ++++++++++
openjdk version "1.8.0_112"
OpenJDK Runtime Environment (build 1.8.0_112-b15)
OpenJDK 64-Bit Server VM (build 25.112-b15, mixed mode)
wrapper home : /opt/traccar
configuration: /opt/traccar/conf/wrapper.conf
openjdk version "1.8.0_112"
OpenJDK Runtime Environment (build 1.8.0_112-b15)
OpenJDK 64-Bit Server VM (build 25.112-b15, mixed mode)
---------- YAJSW SET ENV ----------
YAJSW: yajsw-beta-12.07
OS   : Linux/4.4.31-1-lts/amd64
JVM  : Oracle Corporation/1.8.0_112//usr/lib/jvm/java-8-openjdk/jre/64
Nov 22, 2016 11:19:53 AM org.apache.commons.vfs2.VfsLog info
INFO: Using "/tmp/vfs_cache" as temporary files store.
Nov 22, 2016 11:19:53 AM org.rzo.yajsw.os.posix.PosixService init
WARNING: Error /etc/init.d : is not a directory
************* STARTING traccar ***********************

Nov 22, 2016 11:19:53 AM org.rzo.yajsw.os.posix.PosixService getPid
INFO: wrapper pid file: null
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.rzo.yajsw.boot.WrapperExeBooter.main(WrapperExeBooter.java:49)
Caused by: java.lang.NullPointerException
	at java.io.File.<init>(File.java:277)
	at org.rzo.yajsw.os.posix.PosixService.start(PosixService.java:552)
	at org.rzo.yajsw.wrapper.WrappedService.start(WrappedService.java:402)
	at org.rzo.yajsw.WrapperExe.doStart(WrapperExe.java:488)
	at org.rzo.yajsw.WrapperExe.executeCommand(WrapperExe.java:158)
	at org.rzo.yajsw.WrapperExe.main(WrapperExe.java:124)
	... 5 more

But as you can see no success :(

I am on Archlinux.

@Abyss777
Copy link
Collaborator

There are two options:

  • Install systemd-sysv-generator if it is available for ArchLinux that enable SysVinit compatiblity for systemd
  • Instead of traccar-linux-3.8.zip use traccar-other-3.8.zip and use this traccar.service example Systemd Installation #2570 (comment)

@BotoX
Copy link

BotoX commented Nov 22, 2016

I went for option two and it works fine, thank you!
Maybe a better idea to let systemd handle the java process directly instead of using the traccar.sh script
This way it could also autorestart it etc.

@tananaev
Copy link
Member

The problem is that not all Linux distributions use systemd.

@kirantpatil
Copy link

Systemd is universal now [Redhat, CentOS, Fedora, Opensuse, Arch and so on], even in ubuntu from 16.04 onwards. IMHO it is better to have support for Systemd.

@neilromig
Copy link
Author

Can I ask, for the sake of moving the PID file to its usual /var/run location can I just change the "/tmp" Java argument in traccar.sh to "/var/run" and relocate the PID file?

@tananaev
Copy link
Member

@kirantpatil, I need some statistics. You are talking about latest versions of distros. There are many servers that run older versions or alternative distribution (especially in embedded world).

@neilromig, you can try. It would probably move some other files there as well.

@kirantpatil
Copy link

Systemd adoption of major Linux distributions

screenshot from 2016-11-24 12 02 46

@tananaev
Copy link
Member

So, it was made default in 2015, and it's still not there for Gentoo. I think it's too early for full switch, but maybe it's a good idea to provide a separate installer for it. The main problem is that YAJSW doesn't support it.

@kirantpatil
Copy link

👍 for separate installer

@Abyss777
Copy link
Collaborator

If somebody interested, here is systemd service to use with wrapper:

[Unit]
Description=traccar
[Service]
Type=forking
WorkingDirectory=/opt/traccar
ExecStart=/usr/bin/java -Dwrapper.pidfile=/var/run/wrapper.traccar.pid -Dwrapper.service=true -Dwrapper.visible=false -Djna_tmpdir=/opt/traccar/tmp -jar /opt/traccar/wrapper.jar -tx /opt/traccar/conf/wrapper.conf
ExecStop=/usr/bin/java -Dwrapper.pidfile=/var/run/wrapper.traccar.pid -Dwrapper.service=true -Dwrapper.visible=false -Djna_tmpdir=/opt/traccar/tmp -jar /opt/traccar/wrapper.jar -px /opt/traccar/conf/wrapper.conf
PIDFile=/var/run/wrapper.traccar.pid
SuccessExitStatus=143
TimeoutStopSec=30
[Install]
WantedBy=multi-user.target

Exit code and timeout are adjusted to stop service correctly.

wrapper has some useful features, like writing log, detecting deadlocks and others.

@BotoX
Copy link

BotoX commented Nov 24, 2016

@Abyss777 Getting following error on a systemd only OS (Archlinux)

WARNING: Error /etc/init.d : is not a directory

It works fine after creating /etc/init.d - I guess this is a YAJSW bug(feature?) as it doesn't even touch the folder...
Just something to consider as not every distribution has a /etc/init.d directory.

@tananaev
Copy link
Member

You can probably change directory using wrapper.daemon.dir parameter:

http://yajsw.sourceforge.net/YAJSW%20Configuration%20Parameters.html

@kirantpatil
Copy link

@BotoX any updates on @tananaev suggestion ?

@BotoX
Copy link

BotoX commented Dec 12, 2016

I just created /etc/init.d to solve the issue.
I guess you can change the path to some empty directory in the traccar install path. But the proper solution would be for YAJSW to fix this issue.

@kirantpatil
Copy link

kirantpatil commented Dec 26, 2016

@Abyss777,

I am using your traccar.service code and it is running fine, without any error as below.

Also observed that traccar file is present in /etc/init.d directory.

$ ls /etc/init.d/traccar 
/etc/init.d/traccar

I am using ubuntu 16.04.1 LTS.

$ cat /etc/issue
Ubuntu 16.04.1 LTS \n \l

Please let me know if you want me to check further with systemd related issues.

$ sudo systemctl status traccar.service
● traccar.service - traccar
   Loaded: loaded (/lib/systemd/system/traccar.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2016-12-26 08:47:16 UTC; 23s ago
  Process: 5710 ExecStop=/usr/bin/java -Dwrapper.pidfile=/var/run/wrapper.traccar.pid -Dwrapper.service=true -Dwrapp
  Process: 5734 ExecStart=/usr/bin/java -Dwrapper.pidfile=/var/run/wrapper.traccar.pid -Dwrapper.service=true -Dwrap
 Main PID: 5749 (java)
    Tasks: 57
   Memory: 171.7M
      CPU: 9.812s
   CGroup: /system.slice/traccar.service
           ├─5749 java -Dwrapper.pidfile=/run/wrapper.traccar.pid -Dwrapper.service=true -Dwrapper.visible=false -Dj
           └─5765 java -classpath /opt/traccar/wrapperApp.jar:/opt/traccar/tracker-server.jar:/opt/traccar/lib/log4j

Dec 26 08:47:14 ip-172-31-4-64 java[5734]: Dec 26, 2016 8:47:14 AM org.rzo.yajsw.os.posix.PosixService startProcess
Dec 26 08:47:14 ip-172-31-4-64 java[5734]: INFO: calling java -Dwrapper.pidfile=/run/wrapper.traccar.pid -Dwrapper.s
Dec 26 08:47:14 ip-172-31-4-64 java[5734]: Dec 26, 2016 8:47:14 AM org.rzo.yajsw.os.posix.PosixService getPid
Dec 26 08:47:14 ip-172-31-4-64 java[5734]: INFO: wrapper pid file: /run/wrapper.traccar.pid
Dec 26 08:47:16 ip-172-31-4-64 java[5734]: Dec 26, 2016 8:47:16 AM org.rzo.yajsw.os.posix.PosixService getPid
Dec 26 08:47:16 ip-172-31-4-64 java[5734]: INFO: wrapper pid file: /run/wrapper.traccar.pid
Dec 26 08:47:16 ip-172-31-4-64 java[5734]: Dec 26, 2016 8:47:16 AM org.rzo.yajsw.os.posix.PosixService getPid
Dec 26 08:47:16 ip-172-31-4-64 java[5734]: INFO: wrapper pid file: /run/wrapper.traccar.pid
Dec 26 08:47:16 ip-172-31-4-64 java[5734]: Service traccar started
Dec 26 08:47:16 ip-172-31-4-64 systemd[1]: Started traccar.

ubuntu@ip-172-31-4-64:~$ tail -f /opt/traccar/logs/tracker-server.log 
2016-12-26 08:38:09  INFO: Character encoding: UTF-8 charset: UTF-8
2016-12-26 08:38:09  INFO: Version: 3.9-SNAPSHOT
2016-12-26 08:38:15  INFO: Starting server...
2016-12-26 08:47:06  INFO: Shutting down server...
2016-12-26 08:47:17  INFO: Operating system name: Linux version: 4.4.0-53-generic architecture: amd64
2016-12-26 08:47:17  INFO: Java runtime name: OpenJDK 64-Bit Server VM vendor: Oracle Corporation version: 25.111-b14
2016-12-26 08:47:17  INFO: Memory limit heap: 239mb non-heap: 0mb
2016-12-26 08:47:17  INFO: Character encoding: UTF-8 charset: UTF-8
2016-12-26 08:47:17  INFO: Version: 3.9-SNAPSHOT
2016-12-26 08:47:21  INFO: Starting server...

@Abyss777
Copy link
Collaborator

@kirantpatil thanks for feedback.

/etc/init.d/traccar likely was created by traccar installer

@jzahraoui
Copy link

I've made some modifications to run the service with another user. I'm sharing this to help :

sudo addgroup --system traccar sudo adduser --disabled-password --system --home /opt/traccar --gecos "TracCar" --ingroup traccar traccar


[Unit]
Description=traccar
After=syslog.target mysql.service
Wants = mysql.service

[Service]
RuntimeDirectory=traccar
RuntimeDirectoryMode=0755

User=traccar
Group=traccar

Type=forking
WorkingDirectory=/opt/traccar
# ExecStart=/opt/traccar/bin/traccar start sysd
# ExecStop=/opt/traccar/bin/traccar stop sysd

ExecStart=/usr/bin/java -Dwrapper.pidfile=/var/run/traccar/wrapper.traccar.pid -Dwrapper.service=true -Dwrapper.visible=false -Djna_tmpdir=/opt/traccar/tmp -jar /opt/traccar/wrapper.jar -tx /opt/traccar/conf/wrapper.conf
ExecStop=/usr/bin/java -Dwrapper.pidfile=/var/run/traccar/wrapper.traccar.pid -Dwrapper.service=true -Dwrapper.visible=false -Djna_tmpdir=/opt/traccar/tmp -jar /opt/traccar/wrapper.jar -px /opt/traccar/conf/wrapper.conf

PIDFile=/var/run/traccar/wrapper.traccar.pid
SuccessExitStatus=143
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target

@tananaev
Copy link
Member

tananaev commented Apr 6, 2017

@jzahraoui, thanks for sharing the information.

@alexanderzatko
Copy link

alexanderzatko commented Feb 18, 2019

I am trying to create a systemd drop-in, that would automatically restart the service after crash. The code above contains information I could use in my code, but judging from the fact that paths like /opt/traccar/conf/wrapper.conf no longer exist (at least in version: 4.2), it does not seem applicable any more.

This is what I have:

[Service]
Type=forking
GuessMainPID=yes
RemainAfterExit=no
Restart=no
RestartSec=5s

..but it does not work. Systemd can see the file, but after I crash the service, it does not start back up. Could somebody please give me some pointers about how to make this work?

@alexanderzatko
Copy link

alexanderzatko commented Feb 18, 2019

.. more precisely, I am looking for values for these parameters:

PIDFile (URI)
ExecStart
ExecStop

I "think" the value for the ExecStart and ExecStop is the same and looks like this:

/opt/traccar/jre/bin/java -jar tracker-server.jar conf/traccar.xml

...but the PIDFile value I have no idea what that could be (running Ubuntu 14.04).

@tananaev
Copy link
Member

Recent versions of Traccar use systemd by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants