09-25-2019 03:34 AM
Morning folks,
I've been scratching my head/beard over this for a while and can't seem to resolve it, let me set the scene.
I have a ISR1K with guestshell, I've installed python3 and a few other tools and deployed my flask based app successfully, runs great if I log in to guestshell and run the command
sudo -E python3 myapp.py
The problem arises when I wish to run the app as a service using systemd .service setup I run in to trouble with the environment variable. the -E in the sudo command retains the environment from the current user, transferring all the setting over including the token file to be able to run Cisco CLI commands within python
I have hidden the token: Environment=SHELL_SESSION_host="/cisco/nginx_shared/pnp_python.sock" Environment=SHELL_SESSION_logfile="/cisco/cisco_cli/<<token>>/cisco_cli.log" Environment=SHELL_SESSION_max_wait="3600" Environment=SHELL_SESSION_pnp_listener_path="/pnp_python" Environment=SHELL_SESSION_scheme="unixhttp" Environment=SHELL_SESSION_session_id="<<token>>" Environment=SHELL_SESSION_token_file="/cisco/cisco_cli/<<token>>/token"
I've tried to run the service as guestshell user and the command to run include the /usr/bin/sudo -E command, no dice. I've tried creating an environment file for the systemd settings but as the token seems to be per session I'm not getting anywhere. I've tried creating a startup bash script to run sudo -E but this also fails with errors saying missing 'host' variable in the environment which refers to the SHELL_SESSION_host variable above
Does anyone have any ideas on where I should go next?
Thanks
ps: I have remodeled the cli and pnp python modules to python3 as they are default python 2.7 on guestshell if anyone is interested in it
11-08-2024 09:24 AM - edited 11-08-2024 09:24 AM
Just discover the same problem today. Even if I copy the env, the script stops to work when the user logouts...
Did you found any solution?
11-08-2024 09:24 AM - edited 11-08-2024 09:26 AM
In the ZTP documentation (https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/prog/configuration/166/b_166_programmability_cg/zero_touch_provisioning.html), there are some examples of script running without user involved, but the are run by IOS itself, so the env must be created in this case...
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide