[Linux]Make SS ask for (linux) username and pass at start
Posted: Thu May 05, 2011 2:17 pm
I run SS on a headless server, so since I never reboot that machine I wanted a way to quickly start SS under different user credentials, and asking the pass before going through with it.
For this I modified the subsonic.sh from the standalone package. This is really just basic linux shell code I added, so its not really distribution or SS package related. If it has bash, it will work. Though it's not so practical to use the terminal-sudo in a gui startup situation or for autostart at boot.
So this was made with manual starting and stopping in mind, to potentially add multiple servers to a machine and/or test different user credentials for running SS, permissions etc.
Its also possible to set a fixed user in my version of subsonic.sh and just use the new --user=name parameter to override the default if need be.
Please note, if you dont set the user manually at the top of the script by assigning it to the variable SUBSONIC_USER, you NEED to provide it with the --user=username option. Else SS will fail to start (on purpose, unclear credentials situation). A password for the specified user will have to be entered either way though.
One final note:
Theres currently no error handling done when a user is entered that is not present on the system! Then, SS will _not_ start but it will also _not_ throw an error...Maybe someone can help me out here. This script really was made only for me as a quick fix, but if someone finds it handy thats good too
The "patch" is in noob-form, like this:
find:
replace with:
!!!
PLEASE:
-STOP SERVER
-BACKUP SS FOLDER
-ONLY THEN EDIT FILES
-START SERVER WHEN FINISHED EDITING ONLY
!!!
In subsonic.sh in the SS main directory,
find:
replace with:
find:
replace with:
find:
replace with:
find:
replace with:
EDIT: Why would I want this? So I dont accidently start SS as root, which brings a host of problems with it. Not only is security severely compromised, also all uploaded files will be owned by root which is a bitch if you just want to tag/fix a huge bunch of files and somehow it doesnt work as exected Also, all files created by SS will be owned by root, which is not what I want.
Alternatively you can use this to conveniently start several instances of SS, each from a different user (eg. user private, user public or whatever) without getting too confused.
For this I modified the subsonic.sh from the standalone package. This is really just basic linux shell code I added, so its not really distribution or SS package related. If it has bash, it will work. Though it's not so practical to use the terminal-sudo in a gui startup situation or for autostart at boot.
So this was made with manual starting and stopping in mind, to potentially add multiple servers to a machine and/or test different user credentials for running SS, permissions etc.
Its also possible to set a fixed user in my version of subsonic.sh and just use the new --user=name parameter to override the default if need be.
Please note, if you dont set the user manually at the top of the script by assigning it to the variable SUBSONIC_USER, you NEED to provide it with the --user=username option. Else SS will fail to start (on purpose, unclear credentials situation). A password for the specified user will have to be entered either way though.
One final note:
Theres currently no error handling done when a user is entered that is not present on the system! Then, SS will _not_ start but it will also _not_ throw an error...Maybe someone can help me out here. This script really was made only for me as a quick fix, but if someone finds it handy thats good too
The "patch" is in noob-form, like this:
find:
- Code: Select all
old text
replace with:
- Code: Select all
new text
old text
!!!
PLEASE:
-STOP SERVER
-BACKUP SS FOLDER
-ONLY THEN EDIT FILES
-START SERVER WHEN FINISHED EDITING ONLY
!!!
In subsonic.sh in the SS main directory,
find:
- Code: Select all
SUBSONIC_HOME=/var/subsonic
replace with:
- Code: Select all
SUBSONIC_USER=
SUBSONIC_HOME=/var/subsonic
find:
- Code: Select all
echo " --home=DIR The directory where Subsonic will create files."
replace with:
- Code: Select all
echo " --user=USERNAME Specify the user under which SS shall be run."
echo " --home=DIR The directory where Subsonic will create files."
find:
- Code: Select all
--home=?*)
SUBSONIC_HOME=${1#--home=}
;;
replace with:
- Code: Select all
--user=?*)
SUBSONIC_USER=${1#--user=}
;;
--home=?*)
SUBSONIC_HOME=${1#--home=}
;;
find:
- Code: Select all
${JAVA} -Xmx${SUBSONIC_MAX_MEMORY}m \
replace with:
- Code: Select all
# Test if username was given as Parameter, else exit with error
if [ -z $SUBSONIC_USER ]; then
echo "ERROR: No username given!"
echo "use parameter --user or set the username manually at the top of this script"
echo
usage
exit 1;
fi
su $SUBSONIC_USER -c "${JAVA} -Xmx${SUBSONIC_MAX_MEMORY}m \
-Dsubsonic.home=${SUBSONIC_HOME} \
-Dsubsonic.host=${SUBSONIC_HOST} \
-Dsubsonic.port=${SUBSONIC_PORT} \
-Dsubsonic.contextPath=${SUBSONIC_CONTEXT_PATH} \
-Dsubsonic.defaultMusicFolder=${SUBSONIC_DEFAULT_MUSIC_FOLDER} \
-Dsubsonic.defaultPodcastFolder=${SUBSONIC_DEFAULT_PODCAST_FOLDER} \
-Dsubsonic.defaultPlaylistFolder=${SUBSONIC_DEFAULT_PLAYLIST_FOLDER} \
-Djava.awt.headless=true \
-jar subsonic-booter-jar-with-dependencies.jar > ${LOG} 2>&1 &"
EDIT: Why would I want this? So I dont accidently start SS as root, which brings a host of problems with it. Not only is security severely compromised, also all uploaded files will be owned by root which is a bitch if you just want to tag/fix a huge bunch of files and somehow it doesnt work as exected Also, all files created by SS will be owned by root, which is not what I want.
Alternatively you can use this to conveniently start several instances of SS, each from a different user (eg. user private, user public or whatever) without getting too confused.