Running upstart script on 17.04?

5,044

Solution 1

The above steps worked beautifully, I have made some detailed steps in my answer here:

My env is as follows

  1. Ubuntu at 17.10
  2. I have a python app on Gunicorn 19.x server, I need to start this application as a service.

Firstly you need to write a foo.service file.

[Unit] 
Description=FooServer 

[Service] 
Restart=on-failure
WorkingDirectory=/path/to/your/working/directory/where the foo lives
ExecStart=/what/process/will call foo eg: in my case I used gunicorn app:app
ExecReload=/bin/kill -HUP $MAINPID 
KillSignal=SIGINT 

[Install] 
WantedBy=multi-user.target

The meaning of every word on the left hand side of the '=' sign and their equivalent in (to the earlier) upstart is in link https://wiki.ubuntu.com/SystemdForUpstartUsers

Once the file is ready, let's say you name it as 'foo.service' (the .service extension is important)

You need to place the file in /lib/systemd/system

After which you need to enable the service by calling

systemctl enable foo

Which will prompt you enter your root password as it will be creating symlinks in some root access based folders where all the services party.

If you have reached till here without any hassle , you are good. Your service is hence created. Start it by calling

sudo service foo start

systemctl status foo to see the status sudo service foo stop to stop the service

I was on the Gunicorn page all day today and tried all the various options and none of them worked and finally this one worked. Thank you so much @Zanna and @Nicklas Karlsson

Solution 2

Apparently upstart isn't included in the server version OOTB even though there are scripts in /etc/init (a bit confusing).

I rewrote the upstart script as a systemd unit file using mostly the Ubuntu wiki page on systemd for upstart users as a guide and enabled it in normal fashion.

Share:
5,044

Related videos on Youtube

Nicklas Karlsson
Author by

Nicklas Karlsson

Updated on September 18, 2022

Comments

  • Nicklas Karlsson
    Nicklas Karlsson over 1 year

    Running 17.04 (Zesty Zapus) and trying to start an upstart script but I noticed it's not getting executed. Then I noticed that upstart isn't even listed as an installed package even if there are lots of scripts in /etc/init. Apparently they are not run since introducing a typo in e.g cron doesn't affect its startup.

    How should I run the upstart script? Install upstart or run it through some systemd-layer? Does installing upstart break something when the other scripts in /etc/init are suddenly run?

    • Zanna
      Zanna almost 7 years
      I think systemd does run scripts in /etc/init.d if there is no unit file in /etc/systemd/system or its subdirs. Could you give a little more detail about what you are trying to do?
    • Nicklas Karlsson
      Nicklas Karlsson almost 7 years
      Thanks for the reply. I'm following the tutorial on digitalocean.com/community/tutorials/… on how to run Consul as a service on Ubuntu...
    • Zanna
      Zanna almost 7 years
      Please could you try putting the script in /etc/init.d instead of /etc/init? It will need permissions 755.
    • Nicklas Karlsson
      Nicklas Karlsson almost 7 years
      Nothing happens (I didn't even know upstart-format scripts could be run from init.d)
    • Zanna
      Zanna almost 7 years
      oh hmm I see that just having a script there doesn't tell systemd that there should be such a service, although if it does know there should be such a service, the file in /etc/init/d is used. You might try making a symlink - assuming the script in /etc/init.d is called consul: sudo ln -s /etc/init.d/consul /etc/systemd/system/consul.service
    • Nicklas Karlsson
      Nicklas Karlsson almost 7 years
      Sill no go. But is systemd supposed to be able to execute the upstart-formatted script?
    • Zanna
      Zanna almost 7 years
      I thought it did (SysV, Upstart and systemd init script coexistence), but poking around on my system I see that the scripts in /etc/init.d that I know work without there being any systemd unit file are actually (da)sh scripts. So, maybe you need to "translate" the upstart script into a systemd unit file to get this one to work - see Migrate basic upstart script to systemd
    • Nicklas Karlsson
      Nicklas Karlsson almost 7 years
      OK. Converted my (755) /etc/init.d/consul to systemd syntax [Unit] Description=Consul server Requires=network-online.target After=network-online.target [Service] EnvironmentFile=-/etc/consul.d/consul.env Environment=GOMAXPROCS=2 Restart=on-failure ExecStart=/var/consul/consul agent $OPTIONS -config-dir=/etc/consul.d/bootstrap ExecReload=/bin/kill -HUP $MAINPID KillSignal=SIGINT [Install] WantedBy=multi-user.target and added the symlink from /etc/systemd/system/consul.service but still no evidence that it's trying
    • Zanna
      Zanna almost 7 years
      O.o I am clueless then. The proper location for unit files is /lib/systemd/system (they may need the suffix .service) and then you should run systemctl enable <name of service> which causes a symlink to be made from /etc/systemd/system/foo.service to the real file /lib/systemd/system/foo.service. Do you get anything from systemctl status consul?
    • Nicklas Karlsson
      Nicklas Karlsson almost 7 years
      Getting closer. calling enable gives me "Failed to lookup unit file state: Invalid argument" but calling restart actually starts the service (as root, though). Something in the startup script (I stole off the net), I guess
    • Nicklas Karlsson
      Nicklas Karlsson almost 7 years
      status says ● consul.service - Consul server Loaded: loaded (/etc/init.d/consul; bad) Active: inactive (dead)
    • Zanna
      Zanna almost 7 years
      oh yeah sounds like something needs correction - suggest you edit your question and post the unit file you made and link to the tutorial and post the upstart file so you can get help fixing the issue and all the relevant info is in one place
    • Nicklas Karlsson
      Nicklas Karlsson almost 7 years
      Actually now I got (re-read your post). Putting the script in (only) the lib/systemd/system and then calling systemctl enable did the job. I guess I poked around too much myself, creating colliding symlinks...
    • Zanna
      Zanna almost 7 years
      ah that's awesome! Glad you got it fixed. Maybe you could write an answer explaining how you managed to help someone else...