• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Using python through an event handler, impossible?

L

ledj

Guest
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.
 
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.
 
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 :)
 
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.
 
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.
 
Wups, no relative paths in scripts for use in Plesks event handler. Absolute paths work. I saw that piping error to a log.

Thanks :)
 
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.
 
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.
 
Back
Top