Linux administrative tasks > Init script for python app
Author: Aleksandr Chirkov
Dec. 19, 2013, 2:11 p.m.

Lets make init script for our python app that it starts with system boot. Follow script below:

#!/bin/sh

### BEGIN INIT INFO

# Provides: myservice

# Required-Start: $remote_fs $syslog

# Required-Stop: $remote_fs $syslog

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Short-Description: Put a short description of the service here

# Description: Put a long description of the service here

### END INIT INFO


# Change the next 3 lines to suit where you install your script and what you want to call it

DIR=/usr/local/bin/myservice

DAEMON=$DIR/myservice.py

DAEMON_NAME=myservice


# This next line determines what user the script runs as.

# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.

DAEMON_USER=root


# The process ID of the script when it runs is stored here:

PIDFILE=/var/run/$DAEMON_NAME.pid


. /lib/lsb/init-functions


do_start () {

log_daemon_msg "Starting system $DAEMON_NAME daemon"

start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --startas $DAEMON

log_end_msg $?

}

do_stop () {

log_daemon_msg "Stopping system $DAEMON_NAME daemon"

start-stop-daemon --stop --pidfile $PIDFILE --retry 10

log_end_msg $?

}

case "$1" in

start|stop)

do_${1}

;;

restart|reload|force-reload)

do_stop

do_start

;;

status)

status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $?

;;

*)

echo "Usage: /etc/init.d/$DEAMON_NAME {start|stop|restart|status}"

exit 1

;;

esac

exit 0

 

That's it. Add path to interpreter in python app (e.g.  #!/usr/bin/env python). Make executable both init script and our python app like bellow:

chmod +x /etc/init.d/myservice /usr/local/bin/myservice.py

Add symbolic links for our init script and start our app:

update-rc.d /etc/init.d/myservice defaults && service myservice start

 

After that our app should start and work)

python
daemon
init
Propecia Low Sperm Count Stopped Levitra Originale 5 Mg [url=http://costofcial.com]viagra cialis[/url] Cheapeast Zentel Medication Discount Overseas Amoxicillin No Prescription Abc Pharmacy Canada Kamagra Jelly Usa Buy Cialis With No Prescription online pharmacy Comprare Cialis 20 Mg Venta De Cialis Online Zithromax Time To Work Is Zithromax Available In India Illegal Cialis Refrigeration Of Cephalexin http://costofcial.com - cialis Comprar Cialis Farmacia Barcelona Cialis Eli Lilly
Prezzo Viagra Pfizer Buy Periactins Online [url=http://costofcial.com]cheap cialis[/url] Cycotec Royal Drugstore Online Tadalafil 5mg Buy Online India Fluconazole Order In Usa Cialis Come Prenderlo cialis Isotretinoin Skin Health Priligy Y Epilepsia Achat Cialis Inde Effetti Collaterali Viagra Cialis Amoxicillin Stomach http://costofcial.com - cialis price Cialis Super Active Canada Buy
Cephalexin Atlanta Dental Prescription Free Amoxicillin [url=http://costofcial.com]cialis[/url] Buy Online Lasix Viagra Super Active Plus Review Achat De Valium Pas Cher Meilleure Facon De Durer Plus Longtemps cheap cialis Donde Comprar Cialis Farmacia Progesterone Website Pills C.O.D. No Prescription Buy Stendra Online Cialis Tablets For Sale Au Lasix With No Rx Fast Shipping http://costofcial.com - online pharmacy What Size Fluconazole For A Small Dog Amoxicillin Itchy Bumps Rash Picture Diclofenac Tablets Without Prescription
cialis prescribed for bph buy cialis online effects of cialis and viagra [url=http://cialisoni.com/]cialis online[/url] how long cialis stay in your system
cheap ed meds online ed medicines generic for erectile dysfunction ed medications best ed medication what are the best generic ed drugs online erectile dysfunction medications ed medications compared cheap ed medication ed medications online ed drugs online best erectile dysfunction medication in canada ed drugs meds for ed erectile dysfunction medications sold in canada erectile dysfunction drugs generic ed drugs cheap erectile dysfunction drugs-canada canadian erectile dysfunction drugs ED medication order erectile dysfunction medication generic drugs for erectile dysfunction erectile meds ed drug cost comparison buy erectile dysfunction drugs generic ed medication erectile dysfunction medication prices ed meds on line cheap ed drugs best erectile dysfunction drugs for sale online erectile dysfunction drugs online meds for erectile dysfunction generic ed meds erectile dysfunction drugs canada ed drug best ed drug best deal on ED meds cheap ed meds medication from canada ed erectile dysfunction generic name for ED drugs buy erectile dysfunction drugs online cheap erectile dysfunction medication generic erectile dysfunction medications erectile dysfunction drugs comparison impotence drugs online common drugs for ed generic impotence drugs ed meds cost effective ed drugs canadian erectile dysfunction drugs buy diprosalic no prescription uk viagra vs cialis vs levitra reviews buy amoxicillin canadian pharmacy lexapro no rx needed viagra pfizer sildenafil 100 mg canadian pharmacy online no script samples of viagra and cialis cialis 5 mg best price usa

Leave a comment:

Name
Python
Web development
Review Linux
Administration
Provisioning CVS
Windows AWS
Continuous Integration
NoSql Logging Web Servers FileSystems Scala
accurev ansible apach2 apache api application approaches architecture archivation argparse arguments artifactory automation awk aws backup bash batch-scripting beaver block build built-in caching call captcha cartridge case certificates cgi chain client cloud cloudformation cluster cmd coding collections command-line commands compression conditionals conversion convert cookbook copy counter cron crud css cut cygwin daemon datatype date dd debpackage decorator delattr deploy deque dict distributed-file-systems django DNS domain driver dropbox dump elasticcache elasticsearch encryption exit ext4 extra-tags failover file filename filters for form format freetds functions gerrit getattribute gid git globals glusterfs hardware hook iam indexing inheritance init install job-interview jquery ldap linux list locals logging logs logstash lookup magicmethods mail main-menu metadata metalogger mongodb moosefs mount mssql multiplatform multithreading mysql netcat nginx nosql open-ssh openldap openshift os packaging parse partition path pattern patterns permissions pid pil pip pipe playbook pool post post-commit processes production provisioning proxy putty python python-mysql recursively redirection redis register replication repr restore return review rotation scala script search selenium server setattr settings setup shipper signals singleton slots snapshot socket splunk ssh ssh-key ssl storage str string style subprocess sugar super switch syntactic syntaxhighlighter systeminfo tail tar templatetags time tls tune2fs tuple ubuntu unicode unique unix unixodbc usage usecases uuid uwsgi variable vars version vi virtualenv volume web web-server windows with_items __getattr__