-1

I have a upstart configuration file as shown below which works fine in Ubuntu 14:

#/etc/init/data_server.conf
#sudo start data_server
#sudo stop data_server
#sudo status data_server

start on runlevel [2345]
stop on runlevel [016]

chdir /opt/hold/data_server
respawn

post-start script
    echo "data server started at `date +"%F %T"` on `hostname -f`" | mailx -r "abc@host.com" -s "data server Started" "pqr@host.com"
end script

post-stop script
  sleep 30
end script

limit core unlimited unlimited
limit nofile 100000 100000
setuid goldy
exec ./data_server --init_file=../config/tree.init --port=8080 --dir=/data/hold/ --max_sec=2400 --max_mb=100 --active=5

Now we are moving to Ubuntu 16 so we can't use upstart and looks like we need to use systemd here. What are the changes I need to do to write script in systemd?

I have to make sure whenever system is rebooted or app is killed it should start my systemd script automatically which in turn start my data server.

user1950349
  • 223
  • 1
  • 3
  • 10
  • Please try writing the unit yourself, and ask for help with anything where you run into difficulty. This is not a service for doing your work for you. See the [documentation](https://www.freedesktop.org/software/systemd/man/systemd.service.html). – Michael Hampton Mar 21 '18 at 18:48

1 Answers1

2

Your upstart script will change a lot. You shouldn't need to manually specify so many directives, so it will also be a lot shorter.

Making a process always start on boot and restart when it crashes is a simply one line:

Restart=always

I don't know how many custom changes you need to keep, but at the very minimum, it looks like you'd need to keep the chdir and exec commands.

Here is an example of a basic systemd script for your app:

[Unit]
Description=My-service

[Service]
Type=simple
WorkingDirectory=/opt/hold/data_server
ExecStart=/path/to/data_server --init_file=../config/tree.init --port=8080 --dir=/data/hold/ --max_sec=2400 --max_mb=100 --active=5
Restart=always

[Install]
WantedBy=multi-user.target

I found this to be a handy resource when writing custom unit files: https://www.freedesktop.org/software/systemd/man/systemd.unit.html

BoomShadow
  • 405
  • 1
  • 4
  • 9
  • got it make sense now.. I am gonna check that link.. Also by any chance do you know what I can do for these stuff `limit core unlimited unlimited`, `limit nofile 100000 100000` and `setuid goldy`. – user1950349 Mar 21 '18 at 18:51
  • I don't know much about upstart, so I couldn't advise all the translations. However, if you search that page that I linked, it does talk about setting the UID. It maybe also have info for those other custom directives. – BoomShadow Mar 21 '18 at 18:53
  • 1
    @BoomShadow: AFAIK the `ExecStart` has to start with an absolute path to an executable. – Thomas Mar 21 '18 at 19:10
  • 1
    @Thomas Ah yes, you're right. I forgot about that. Thanks. I updated my answer with generic example. – BoomShadow Mar 21 '18 at 20:37