1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

Using python through an event handler, impossible?

Discussion in 'Plesk for Linux - 8.x and Older' started by ledj, Dec 27, 2007.

  1. ledj

    ledj Guest

    0
     
    Hello

    I've made a python script which configures Plesk to use PHP as CGI through mod_fcgid. The script configures and creates a php.ini file, a php wrapper script (also setting immutable bit etc.), and vhost.conf (all created from templates) for every domain. It's all nice and works very nice.

    I've tested it manually, and now I want to use the python script in an event handler (physical hosting created/updated), but I can't get the python script to work in the event handlers.

    It simply won't execute the script, I've tried several things... Calling the python script from inside a normal bash shell script etc.

    I can, however, easily do it with a normal shell script, but as the python script does some pretty neat stuff I aim to use the python script instead.

    How do I use it? Or is it impossible? (seems to me that it is :S)

    Thanks.
     
  2. atomicturtle

    atomicturtle Golden Pleskian

    29
     
    Joined:
    Nov 20, 2002
    Messages:
    2,110
    Likes Received:
    7
    Location:
    Washington, DC
    So its executing your bash script right? My first guess would be that the environment used in the event handler is incomplete. Are you catching any exceptions from python?

    One way I handle execution events in ASL is I run them through sudo (using NOPASSWD), so I can enforce the environment and bypass any other internal plesky-API weirdness. Not exactly a 1 to 1 with what you're doing here, but it might be a diagnostic step. Theres also a logging shell, called sudosh that would let you catch whats being passed through it. I use that for debugging all the time.
     
  3. ledj

    ledj Guest

    0
     
    Yes, it's running the bash script just fine, but it will not execute the python script for some reason.

    Could you point me to some info (if it exists for Plesk) for using the sudo method and sudosh?

    Thanks :)
     
  4. atomicturtle

    atomicturtle Golden Pleskian

    29
     
    Joined:
    Nov 20, 2002
    Messages:
    2,110
    Likes Received:
    7
    Location:
    Washington, DC
  5. ledj

    ledj Guest

    0
     
    Hehe, I guess there's no easy way to get you to work for me ;)

    Nothing fancy in the bash script:

    #!/bin/bash
    echo ${NEW_SYSTEM_USER} >> /root/bin/user_based_vhost/user_based_vhost.log
    echo ${NEW_DOMAIN_NAME} >> /root/bin/user_based_vhost/user_based_vhost.log
    /usr/bin/python2.4 /root/bin/user_based_vhost/user_based_vhost.py ${NEW_SYSTEM_USER} ${NEW_DOMAIN_NAME}

    The python script doesn't execute, which I can probably debug/solve by using your suggestion, I've never used sudo to anything else but doing root commands on ubuntu :D

    The echo of ${NEW_SYSTEM_USER} and ${NEW_DOMAIN_NAME} gets logged just fine.

    Seems like I have to dig into some sudo pretty soon.

    Thanks.
     
  6. atomicturtle

    atomicturtle Golden Pleskian

    29
     
    Joined:
    Nov 20, 2002
    Messages:
    2,110
    Likes Received:
    7
    Location:
    Washington, DC
    Have you tried this to catch the output:

    /usr/bin/python2.4 /root/bin/user_based_vhost/user_based_vhost.py ${NEW_SYSTEM_USER} ${NEW_DOMAIN_NAME} > /tmp/out.log 2>&1

    If you want to shoot me your code, I can take a crack at debugging it here.
     
  7. ledj

    ledj Guest

    0
     
    Wups, no relative paths in scripts for use in Plesks event handler. Absolute paths work. I saw that piping error to a log.

    Thanks :)
     
  8. atomicturtle

    atomicturtle Golden Pleskian

    29
     
    Joined:
    Nov 20, 2002
    Messages:
    2,110
    Likes Received:
    7
    Location:
    Washington, DC
    That was my guess too, its the same problem with cron jobs.

    So now that you've got it working, are you planning on sharing it? Sounds like a pretty handy package.
     
  9. ledj

    ledj Guest

    0
     
    Yes, I will share it with anyone who are interested. But be aware that it's only tested on Centos 5.x although it could probably be ported to other linux dists with ease...

    I don't know where to post it, maybe I'll upload the script somewhere and post a link here...
    But before I do that, I plan to make a vhost.ini which is placed in conf folder along vhost.conf file. vhost.ini will contain an ini-style configuration of the vhost, with max cgi-childs, cgi-requests and php.ini settings for each vhost (every vhost has its own php.ini)...

    But maybe I could mail it to you before releasing it... to do som initial testing?

    Thanks.
     
  10. atomicturtle

    atomicturtle Golden Pleskian

    29
     
    Joined:
    Nov 20, 2002
    Messages:
    2,110
    Likes Received:
    7
    Location:
    Washington, DC
Loading...