Followed the documentation for Installing orientdb on Linux/Ubuntu on the following location, http://orientdb.com/docs/2.1/Unix-Service.html
Set the following variables : JAVA_HOME, JRE_HOME, ORIENTDB_HOME and the following changes in the below files,
orientdb.sh
#!/bin/sh
# OrientDB service script
#
# Copyright (c) Orient Technologies LTD (http://www.orientechnologies.com)
# chkconfig: 2345 20 80
# description: OrientDb init script
# processname: orientdb.sh
# You have to SET the OrientDB installation directory here
ORIENTDB_DIR="/local/some-location"
ORIENTDB_USER="some-user"
Installing for systemmd
/etc/systemd/system/orientdb.service
[Unit]
Description=OrientDB Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
Type=forking
ExecStart=/local/some-location/bin/orientdb.sh start
ExecStop=/local/some-location/bin/orientdb.sh stop
ExecStatus=/local/some-location/bin/orientdb.sh status
It is possible to start the service by the following command
systemctl start orientdb.service
But the service will not stop after giving the following command
systemctl stop orientdb.service
Machine Info :
Java 8.0_31
Orientdb 2.1.12
Ubuntu 15.04 on Virtual Box VM
modify your service file according to this:
$ cat /etc/systemd/system/orientdb.service
[Unit]
Description=OrientDB Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=<USER>
Group=<GROUP>
ExecStart=<ORIENTDB_INSTALL_PATH>/bin/server.sh
SuccessExitStatus=143
modifying with your user,group and path.
than reload the service systemctl daemon-reload
Using this is working for me on Fedora23.
Let me know.
Ivan
EDIT
Tried on Ubuntu 15.04 and it works.
There is an issue with shutdown on 2.1.x See: Joe Taras comment. You should update to the latest 2.2.x version.
Related
So I installed Redis and try to start it using systemctl. It stuck at activating service, But however Redis server is already up and running. After that it got SIGTERM scheduling shutdown and restart again and again, forever.
This is my service file.
[Unit]
Description=Advanced key-value store
After=network.target
Documentation=http://redis.io/documentation, man:redis-server(1)
[Service]
Type=forking
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
PIDFile=/var/run/redis/redis-server.pid
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=2755
UMask=007
PrivateTmp=yes
LimitNOFILE=65535
PrivateDevices=yes
ProtectHome=no
##ReadOnlyDirectories=/
ReadWritePaths=-/var/lib/redis
ReadWritePaths=-/var/log/redis
ReadWritePaths=-/var/run/redis
NoNewPrivileges=true
CapabilityBoundingSet=CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE
MemoryDenyWriteExecute=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictNamespaces=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
# redis-server can write to its own config file when in cluster mode so we
# permit writing there by default. If you are not using this feature, it is
# recommended that you replace the following lines with "ProtectSystem=full".
ProtectSystem=true
ReadWriteDirectories=-/etc/redis
[Install]
WantedBy=multi-user.target
Alias=redis.service
I was trying to set up a Twonky Server on Ubuntu. The server works fine, but I could not get systemd to autostart the server (using a service file I created at /etc/systemd/system/twonkyserver.service). Sometimes I got the cryptic error message that some PID-file (/var/run/mediaserver.pid) is not accessible, the exit code of the service is 13, which apparently is a EACCES Permission denied error . The service runs as root.
I finally managed to fix the problem by setting PIDFile in the twonkyserver.service file to /var/run/mediaserver.pid. For reference, find the service file below:
[Unit]
Description=Twonky Server Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/twonky/twonky.sh start
ExecStop=/usr/local/twonky/twonky.sh stop
ExecReload=/usr/local/twonky/twonky.sh reload
ExecRestart=/usr/local/twonky/twonky.sh restart
PIDFile=/var/run/mediaserver.pid
Restart=on-failure
[Install]
WantedBy=multi-user.target
As described above, the below service file auto-starts the Twonky Server on boot. Simply create it using vim /etc/systemd/system/twonkyserver.service. This assumses that you have installed the Twonky Server to usr/local/twonky. The shell-file twonky.sh already provides a nice interface to the service file (twonky.sh start|stop|reload|restart, also see twonky.sh -h).
[Unit]
Description=Twonky Server Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/twonky/twonky.sh start
ExecStop=/usr/local/twonky/twonky.sh stop
ExecReload=/usr/local/twonky/twonky.sh reload
ExecRestart=/usr/local/twonky/twonky.sh restart
PIDFile=/var/run/mediaserver.pid
Restart=on-failure
[Install]
WantedBy=multi-user.target
I would slightly amend the start and stop commands from twonky.sh and put them directly into the twonky.service file for systemd:
[Unit]
Description=Twonky Server Service
After=network.target
[Service]
Type=simple
#Systemd will ensure RuntimeDirectory for the PID file is created under /var/run
RuntimeDirectory=twonky
PIDFile=/var/run/twonky/mediaserver.pid
# use the -mspid argument for twonkystarter to put the pid file in the right place
ExecStart=/usr/local/twonky/twonkystarter -mspid /var/run/twonky/mediaserver.pid -inifile /usr/local/twonky/twonkyserver.ini -logfile /usr/local/twonky/twonky.log -appdata /usr/local/twonky
ExecStop=kill -s TERM $MAINPID
ExecStopPost=-killall -s TERM twonkystarter
ExecStopPost=-killall -s TERM twonky
# Twonky 8.5.1 doesn't reload, it stops instead (on arm at least)
# ExecReload=kill -s HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
You need to be sure the paths in the ExecStart command match where you unpacked twonky, and also where you want the .pid file, configuration, logfile and runtime appdataunless you are happy with their default locations.
After putting that all into/etc/systemd/system/twonky.server, run
sudo systemctl daemon-reload
sudo systemctl start twonky
sudo systemctl enable twonky
my vps in centos 7 ,
I have applications developed in java, 3 files .jar .
I need to run this files when my vps start or log-in, like example "java -jar file-name"
how i can run that file like service
i have the second question is,
what is the file in centos that has the list of services that run when you start centos.
For edit that file and add my jar. files
The second questions:
CentOS uses systemd to start system-wide or user-defined services. You can use systemctl to find out. For example, checking out the SSH server daemon, we can do:
[user1#centos Good]$ systemctl | grep ssh
sshd.service loaded active running OpenSSH server daemon
You can write your own .service file and put it under one of the following directories to make your java program run like a service.
/usr/lib/systemd/system/
/lib/systemd/system/
To know more about systemd and .service file, you can check CentOS / RHEL 7 : Beginners guide to systemd
edit: 2019-11-13 18:53:47
//java_program.service
[Unit]
Description=java_program
[Service]
Type=simple
User=root
ExecStart=/usr/bin/java -jar /root/folder/name.jar
RestartSec=5
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
Place java_program.service at path /usr/lib/systemd/system/java_program.service
Run command:
sudo systemctl enable java_program
sudo systemctl start java_program
I am following http://masnun.rocks/2016/11/02/deploying-django-channels-using-daphne this tutorial to deploy Django channel on Nginx.In this tutorial, they used upstart script to run daphne serve.I need to convert upstart script to systemd because i am working on ubuntu 16.04.
Below is upstart script
start on runlevel [2345]
stop on runlevel [016]
respawn
script
cd /home/ubuntu/Project/projectname
export DJANGO_SETTINGS_MODULE="projectname.settings"
exec daphne -b 0.0.0.0 -p 8001 projectname.asgi:channel_layer
end script
Below is systemd script which i converted
[Unit]
Description=daphne server script
[Service]
Environment=DJANGO_SETTINGS_MODULE="projectname.settings"
WorkingDirectory=/home/ubuntu/Project/projectname
ExecStart=daphne -b 0.0.0.0 -p 8001 projectname.asgi:channel_layer
Restart=always
[Install]
WantedBy=multi-user.target
When i run systemd service status it gave me below error
Failed to get properties: No such interface ''
From man systemd.service in the section on ExecStart=:
For each of the specified commands, the first argument must be an absolute path to an executable.
You have other problems, but first you need to provide a full path to daphne. You can check your file with:
systemd-analyze verify /path/to/your/file.service
I have a spring boot executable jar in a digital ocean droplet. I'm able to execute the jar using java -jar myapp.jar Now I want to have i run as a service.
I've created the file /etc/systemd/system/myapp.service with these contents
[Unit]
Description=myapp
After=syslog.target
[Service]
User=kevin
ExecStart=/var/myapp/myapp-backend-1.0-SNAPSHOT.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
Then enabled it to start at system startup
systemctl enable myapp.service
I'm now attempting to start the service
systemctl start myapp.service
But I'm getting this error
Failed to start myapp.service: Unknown unit: myapp.service
See system logs and 'systemctl status myapp.service' for details.
running systemctl status myapp.service return this:
Failed to get properties: No such interface ''
Try this :
[Unit]
Description=myapp
After=syslog.target
[Service]
User=kevin
ExecStart=java -jar /var/myapp/myapp-backend-1.0-SNAPSHOT.jar
SuccessExitStatus=143
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
I have add :
java -jar in youre ExecStart
Restart=always => If java crack, systemd restart the service
RestartSec=5 => After crash the service restart avec 5 seconds
After youre modification, reload the systemd daemon :
systemctl daemon-reload
Enable on startup :
systemctl enable myapp.service
And start now :
systemctl start myapp.service
You need a wrapper script for the jar mentioned in ExecStart to handle start, stop and restart methods.
Extensive instructions and an example script can be found here