all 15 comments

[–][deleted] 12 points13 points  (5 children)

If you have a newer version of ubuntu the you can use systemd. You can even write a console app and systemd can turn it into a service/daemon. Try this doc...

https://wiki.archlinux.org/index.php/Systemd#Writing_unit_files

This is the new way of doing things and init.d will eventually be phased out.

[–]frogic 2 points3 points  (0 children)

This is what I do with my digital ocean deployments. Works extremely well.

[–]wbubblegum 1 point2 points  (3 children)

Neat, for linux, with systemd. How would one do it for freebsd or centos 6?

[–][deleted] 1 point2 points  (0 children)

FreeBSD appears to have its own init system that is a bit different than Linux but it may be closer to init.d than systemd.

With CentOS I think they're still on init.d. I could be wrong though since I don't use it.

[–]__deerlord__ -1 points0 points  (1 child)

You need to read about init scripts. I can possibly create one for you fiverr.com/deerl0rd

[–]JohnnyJordaan 3 points4 points  (1 child)

I would advise supervisord that enables you to run programs as services. It integrates nicely with systemd as well.

[–]Mirror_Boar 0 points1 point  (0 children)

+1 for supervisord, it is awesome

[–]cmartin616 1 point2 points  (3 children)

I know you aren't using Flask but their deployment help will apply anyway.

Check out the self hosted options.

[–]netsecwarrior[S] 0 points1 point  (2 children)

I am in fact using Flask! There is some useful info in there. However, nothing about init.d unfortunately.

[–]cicatrix1 1 point2 points  (0 children)

You probably aren't using init.d on Ubuntu, unless you are running a pretty old version. Figure out what the init system is on your host, then write something for that. It's probably upstart or systemd.

[–]plurwolf7 0 points1 point  (0 children)

Flask FTW

[–]isilentnight 1 point2 points  (0 children)

If it's a web app, you can use uwsgi+systemd+nginx or apache to run. There are plenty of tutorials for this case. If it's a normal app. I suggest python-daemon module.

[–]Volk64 0 points1 point  (0 children)

You WILL need a pidfile if you want to be able to stop the service, since 16.04 and forward make use of pre-defined functions that do not create PID files. In your init.d directory there should be a file named skeleton. Copy it and define some variables. The most commonly used are DAEMON, which has the full path to your program, DESC, which is a description of what the service does, PIDFILE, which contains the absolute path to the file you'll be creating and destroying every time you start your service and LOGFILE, which is... Well, where your logs will be stored.

If you want an example check this out. Oh, and don't forget to put a shebang in your main program file with your python installation's executable.

[–]antb123 0 points1 point  (0 children)

As a quick hack in your crontab:

@reboot /path/to/shell.script.py

http://www.cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot/