I just switched to 16.04 server from 14.04 server. With Upstart I used to start my server with a file that I had in /etc/rcS.d called M95. M95 was called by /etc/rc.local. Now with systemd I have written a file in /etc/systemd/system called my.service. It looks like this:
[Unit]
Description=MyService
[Service]
WorkingDirectory=/etc
ExecStart=/bin/sh rc.local
[Install]
WantedBy=multi-user.target
When I type "/bin/sh rc.local" into the command line my server does start. When I try to start the service by doing "systemctl start my.service" nothing happens.
The relevant lines in journalctl -b are:
Started MyService.
eth0 ...(basically the info I see from ifconfig)
root : TTY=unknown ; PWD=/etc ; USER=root ; COMMAND=/etc/rcS.d/M95
pam_unix(sudo:session): session opened for user root by (uid=0)
$File not found:: /new/den-routes
udhcpd already running
pam_unix(sudo:session): session closed for user root
/bin/rm: cannot remove '/var/log/rewriting-net-rules': No such file or directory.
In rc.local it looks like:
#!/bin/sh -e
...
sudo /etc/rcS.d/M95
/bin/rm /var/log/rewriting-net-rules
exit 0
In M95 it starts udhcpd (which is where the "udhcpd already running" message comes from) and at the end starts the server by saying:
cd /new
/bin/sh StartServer&
It seems that it does get to M95 because messages are getting logged from it, but the server does not start. When I run these files in the command line it works, but as the service it does not work. I am very unfamiliar with systemd so I have no idea if I am doing this correctly. For a week I have been reading examples and tutorials for it but I am still unsure how this works and how the service file should be written.
Edit: Here is my StartServer file:
#!/bin/bash
nohup /jre/jdk1.8.0_101/jre/bin/myserver -Xrs -Xmx1000m -jar /new/MyServer.jar nowd &
It runs just fine when I start it from the command line. It runs when I call it from my.service. I put in some echos to see that it gets through the whole file, but myserver and MyServer.jar don't start for some reason.