How to add a python program to run on startup the cli way

To make a python program run on startup..first create o file on /etc/ creating a file named timestamp.

touch /etc/init.d/timestamp

Now edit the file

vim  /etc/init.d/timestamp

and enter the following

#! /bin/bash
# Copyright (c) 1996-2012 My Company.
# All rights reserved.
# Author: Ganesh H, 2013
# Please send feedback to
# /etc/init.d/timestamp
# Provides: timestamp
# Required-Start: 
# Should-Start: 
# Required-Stop: 
# Should-Stop:
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Short-Description: Test daemon process
# Description:    Runs up the test daemon process

# Activate the python virtual environment
#    . /path_to_virtualenv/activate

case "$1" in
    echo "Starting server"
    # Start the daemon 
    /usr/bin/python /home/ganesh/Pictures/ start
    echo "Stopping server"
    # Stop the daemon
    /usr/bin/python /home/ganesh/Pictures/ stop
    echo "Restarting server"
    /usr/bin/python /home/ganesh/Pictures/ restart
    # Refuse to do other stuff
    echo "Usage: /etc/init.d/timestamph {start|stop|restart}"
    exit 1

exit 0

give the correct path of the file..Now make the init.d file executable

chmod +x /etc/init.d/timestamp

Now add the script to bootup

sudo update-rc.d timestamp  defaults

or you can use chkconfig

chkconfig --add timestamp

To remove the startup

rm -fv /etc/rc*/*timestamp


chkconfig --del timestamp

To view all configured startup use the below command

chkconfig --list

Happy Hacking 🙂


2 thoughts on “How to add a python program to run on startup the cli way

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s