Wednesday 19 August 2015

Send email from script

Install ssmtp:

    $ sudo apt-get install ssmtp

Edit the ssmtp config file:

    $ sudo vim /etc/ssmtp/ssmtp.conf

Enter this in the file:

root=username@gmail.com
mailhub=smtp.gmail.com:465
rewriteDomain=gmail.com
AuthUser=username
AuthPass=password (create a app-specific password in google accounts)
FromLineOverride=YES
UseTLS=YES

Enter the email address of the person who will receive your email:

    $ ssmtp recepient_name@gmail.com

Now enter this:

To: recipient_name@gmail.com
From: username@gmail.com
Subject: Sent from a terminal!

Your content goes here. Lorem ipsum dolor sit amet, consectetur adipisicing.
(Notice the blank space between the subject and the body.)

To send the email: Ctrl + D

You can also save the text mentioned in Point 5 into a text file and send it using:

    $ ssmtp recipient_name@gmail.com < filename.txt

http://askubuntu.com/questions/12917/how-to-send-mail-from-the-command-line

Friday 7 August 2015

Supervisord & Rundeck

supervisord

install

$ sudo easy_install supervisor

generate SHA-1 hash of password to be used for TCP access

$ echo -n password | sha1sum | awk '{print $1}'

enable TCP access

sudo vim /etc/supervisor/supervisord.conf

[inet_http_server]
port = 127.0.0.1:9001
username = user
password = {SHA}1235678

configure supervisorctl command line access (note password cannot be SHA hash, has to be plaintext)

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
serverurl=http://localhost:9001
username = user
password = abcdef

add a program

sudo vim /etc/supervisor/conf.d/app_example.conf

[program:app_example]
command=app_example
directory=/path/to/app
autostart:false
autorestart:false
startsecs:5
startretries:3
user:prod
redirect_stderr:true
stdout_logfile:/path/to/app/logfile.log
stdout_logfile_maxbytes:1000GB

supervisorctl - enter interactive mode

supervisorctl -s http://localhost:9001 -u user -p password

start/stop

    supervisorctl -s http://localhost:9001 -u user -p password start group:app

reread/restart/update

supervisorctl -s http://localhost:9001 -u user -p password update (or reread, restart)

reread just reads config changes, but doesn’t restart any affected processes
restart restarts the names process without loading any config changes
update rereads and restarts apps with changed configuration

rundeck

download and install from http://rundeck.org/downloads.html

add user to rundeck group

$ sudo usermod -a -G rundeck steve

add write permissions to rundeck group

$ sudo chmod g+w -R /var/rundeck