Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Add instructions to start as a service #10

Open
mmccool opened this issue Oct 29, 2017 · 3 comments
Open

Add instructions to start as a service #10

mmccool opened this issue Oct 29, 2017 · 3 comments

Comments

@mmccool
Copy link

mmccool commented Oct 29, 2017

I want this to start as a service whenever the gateway reboots. To get this to work some specific settings are needed. It would be useful to include a systemd service file in the distribution and some instructions on how to install it. I'm using the following but it may or may not have all the things needed (for example, cleanup of the db on shutdown, restart on crash, etc):

[Unit]
Description=Thing Directory
Requires=network.target
After=network.target

[Service]
#Restart=always
#RestartSec=20
User=thingdirectory
ExecStart=/usr/bin/java -jar /opt/thingweb-directory/build/libs/thingweb-directory-0.7.jar -c 15683 -h 8080 -d /opt/thingweb-directory/db -l /opt/thingweb-directory/Lucene /opt/thingweb-directory

[Install]
WantedBy=multi-user.target

Note I run this with an account with normal user privileges created for the purpose. To install, copy the above to /etc/systemd/system/thing-directory.service and invoke

sudo systemctl enable thing-directory.service
sudo systemctl start thing-directory.service

Also, the following commands are useful for monitoring the service:

sudo systemctl status thing-directory
sudo journalctl -u thing-directory.service

And for shutting it down/turning off automatic startup on boot:

sudo systemctl stop thing-directory.service
sudo systemctl disable thing-directory.service

~

@mmccool
Copy link
Author

mmccool commented Oct 29, 2017

Note also the various options (-c, -h, -d, -l) to start the service. These should also be documented somewhere. The first two are useful to remap ports. It turns out the last two MUST be specified for the service to work as they by default try to create files in / (which won't work unless you run the service as root, which is unnecessary and unsafe).

@mmccool
Copy link
Author

mmccool commented Oct 29, 2017

I also install the thingweb-directory github clone under /opt/thingweb-directory. Another option (maybe better) would be to put it under /home/thingdirectory, the home directory of the user that runs the service.
Yet another option would be to put the whole thing in a container (either a snap or a docker container).

@mmccool
Copy link
Author

mmccool commented May 13, 2018

For the updated version (binary release) I am now using the following:

[Unit]
Description=Thing Directory Service
Requires=network.target
After=network.target

[Service]
Restart=always
RestartSec=20
User=thingdirectory
ExecStart=/home/thingdirectory/thingweb-directory-0.8.1/bin/thingweb-directory -h 8070 

[Install]
WantedBy=multi-user.target

Note the use of a special account (with minimum privileges) to run. I also give an example of mapping it to a different port. The documentation can show this but perhaps use the default port. My previous comments about documenting the options somewhere is still relevant (yes, they are available with -help, but that is annoying).

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

No branches or pull requests

1 participant